Android 按钮显示在图形布局中但不显示在设备上(这不是重复的)
Android Button shows in graphical layout but not on device ( This is not duplicate )
按钮在 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。
最后我找到了那个问题的答案,问题是 android 工作室创建了两个同名的 xml 文件 我在一个 xml 文件中添加了按钮但没有意识到是另一个 xml 这就是按钮不可见的原因。将按钮添加到 2 xml 个文件后,它开始显示按钮
android 工作室创建的额外文件在括号中包含 v21,这意味着 当 运行 您的应用程序在 [=18] 上时将使用的那些资源=] 21级或更高。
按钮在 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。
最后我找到了那个问题的答案,问题是 android 工作室创建了两个同名的 xml 文件 我在一个 xml 文件中添加了按钮但没有意识到是另一个 xml 这就是按钮不可见的原因。将按钮添加到 2 xml 个文件后,它开始显示按钮
android 工作室创建的额外文件在括号中包含 v21,这意味着 当 运行 您的应用程序在 [=18] 上时将使用的那些资源=] 21级或更高。