【发布时间】:2021-07-07 03:58:32
【问题描述】:
该按钮在 android 布局中可见,但在设备上不可见。有人说要使用布局检查器布局检查器仅显示设备中可见的内容,如果按钮在设备中不可见,我如何使用布局检查器找到解决方案? (即使在布局检查器中按钮也不可见)
这是xml最后出现的按钮不可见的东西。这是xml代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".PlayerActivity"
android:background="@color/bg"
android:orientation="vertical"
android:weightSum="10"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:gravity="center"
android:orientation="vertical"
android:layout_weight="7"
>
<TextView
android:id="@+id/txtsn"
android:marqueeRepeatLimit="marquee_forever"
android:ellipsize="marquee"
android:padding="10dp"
android:singleLine="true"
android:text="@string/song_name_playing"
android:textAlignment="center"
android:textColor="@color/white"
android:textSize="20sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:fontFamily="@font/cooljazz"
android:gravity="center_horizontal" />
<ImageView
android:id="@+id/imageview"
android:layout_marginBottom="20dp"
android:layout_width="250dp"
android:layout_height="250dp"
android:src="@drawable/music_icon"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="20dp"
>
<SeekBar
android:id="@+id/seekbar"
android:layout_centerInParent="true"
android:layout_alignParentBottom="true"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:layout_marginBottom="2dp"
>
</SeekBar>
<TextView
android:id="@+id/txtsstart"
android:layout_toLeftOf="@id/seekbar"
android:layout_centerInParent="true"
android:layout_alignParentRight="false"
android:layout_marginRight="0dp"
android:text="@string/start_time"
android:padding="1dp"
android:layout_marginEnd="5dp"
android:layout_alignParentEnd="false"
android:textColor="#FFF"
android:textSize="14sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toStartOf="@id/seekbar">
</TextView>
<TextView
android:id="@+id/txtsstop"
android:layout_toRightOf="@+id/seekbar"
android:layout_centerInParent="true"
android:layout_alignParentRight="false"
android:layout_marginRight="0dp"
android:text="@string/end_time"
android:padding="1dp"
android:layout_marginEnd="5dp"
android:layout_alignParentEnd="true"
android:textColor="#FFF"
android:textSize="14sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@+id/seekbar">
</TextView>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
tools:ignore="Suspicious0dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<Button
android:id="@+id/playbtn"
app:backgroundTint="@null"
android:layout_centerHorizontal="true"
android:background="@drawable/ic_pause"
android:layout_width="70dp"
android:layout_height="70dp"
/>
<Button
android:id="@+id/btnnext"
android:layout_toRightOf="@+id/playbtn"
android:layout_marginTop="12dp"
android:background="@drawable/ic_next"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_toEndOf="@+id/playbtn">
</Button>
<Button
android:id="@+id/btnprev"
android:layout_toLeftOf="@+id/playbtn"
android:layout_marginTop="12dp"
android:background="@drawable/ic_prev"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_toStartOf="@+id/playbtn">
</Button>
<Button
android:id="@+id/repeatbtn"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentTop="true"
android:backgroundTint="@color/red"
android:layout_marginTop="25dp"
android:layout_marginRight="37dp"
android:layout_toLeftOf="@id/btnprev"
android:background="@drawable/ic_repeat"
android:paddingLeft="20dp"
android:layout_marginEnd="37dp"
android:layout_toStartOf="@id/btnprev"
android:paddingStart="20dp"
tools:ignore="RtlSymmetry">
</Button>
<Button
android:id="@+id/recentstext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="310dp"
android:layout_marginLeft="162dp"
android:layout_marginBottom="0dp"
android:layout_marginTop="10dp"
android:text="@string/recents"
/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
这里是resulted view。
这里是expected view。
【问题讨论】:
-
你还没有提到你在布局检查器中发现了什么?还是您没有检查是因为您认为自己找不到任何东西?
-
按钮在布局检查器中也不可见
-
@HenryTwist 那个布局有问题吗?按钮在检查器中也不可见
标签: android xml android-studio button layout