Android 安卓:为什么赢了';t框架布局中按钮上方的文本视图堆栈
几乎每一篇关于分层小部件主题的文章都会引出框架布局,框架布局应该按照XML中的发生顺序进行堆叠。为了测试,我在xml中放置了一个按钮和一个TextView,希望看到TextView与按钮重叠。无论按钮放在文本视图之前还是之后,按钮始终位于顶部。有人能看出我做错了什么吗Android 安卓:为什么赢了';t框架布局中按钮上方的文本视图堆栈,android,android-framelayout,Android,Android Framelayout,几乎每一篇关于分层小部件主题的文章都会引出框架布局,框架布局应该按照XML中的发生顺序进行堆叠。为了测试,我在xml中放置了一个按钮和一个TextView,希望看到TextView与按钮重叠。无论按钮放在文本视图之前还是之后,按钮始终位于顶部。有人能看出我做错了什么吗 <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/andr
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.jdot.testloadingfragments.MainActivity">
<Button
android:id="@+id/btn_test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:text=" "
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="----------------------------------------------------------"/>
</FrameLayout>
将
立面添加到文本视图将使其显示在按钮上方
e、 g
此处的更多信息:理想情况下,FrameLayout用于显示单个项目
如果要在框架布局中显示多个子视图,请尝试对每个子视图使用android:Layout\u gravity
属性来正确定位它们而不重叠,如果希望视图彼此重叠,请使用立面
更多信息
访问我知道标高,但我不能将我的应用程序限制为API 21+尝试使用app:elevation属性来克服该限制。谢谢。我在避免仰角,但不知道那个按钮是特例。AppCompat的主题会迫使您对公共设计元素使用更为当前的API级别,这是没有意义的。
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.jdot.testloadingfragments.MainActivity">
<Button
android:id="@+id/btn_test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:text=" "/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:elevation="2dp"
android:text="----------------------------------------------------------"/>
</FrameLayout>