我有一个RelativeLayout作为父布局。在它中我有两个按钮和一个FrameLayout。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="button 1"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="button 2"
android:layout_below="@+id/button1"/>
<FrameLayout
android:background="@color/blue"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
FrameLayout的宽度和高度都是match_parent,但我不明白它为什么没有覆盖按钮。
如何遮盖按钮?
答案 0 :(得分:3)
试试这段代码,我测试了它。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="button 1" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/button1"
android:layout_margin="10dp"
android:text="button 2" />
</RelativeLayout>
<FrameLayout
android:background="@color/colorAccent"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
</RelativeLayout>
答案 1 :(得分:0)
您可以将按钮放在LinearLayout
内,它应该可以正常工作。
<强>例如: - 强>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_margin="10dp"
android:text="button 1" />
<Button
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="@+id/button1"
android:layout_margin="10dp"
android:text="button 2" />
</LinearLayout>
答案 2 :(得分:0)
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="button 1" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/button1"
android:layout_margin="10dp"
android:text="button 2" />
</RelativeLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/blue">
</FrameLayout>
现在代码可以正常工作。
答案 3 :(得分:0)
您在主根布局中添加了两个按钮,这将始终保持,使另一个视图为相对或线性,并将它们都放在此内,因此如果匹配,此视图将按框架重叠家长。保持相对布局中的其他视图并单独Framelayout
,看看
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="null"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="button 1" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/button1"
android:layout_margin="10dp"
android:text="button 2" />
</RelativeLayout>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/blue"
android:minHeight="500dp">
</FrameLayout>
</RelativeLayout>
希望它能帮到你!!
答案 4 :(得分:0)
布局可以隐藏布局 ..所以要隐藏同一布局中的按钮,你必须用另类布局包裹按钮 ..: - < / p>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="button 1"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="button 2"
android:layout_below="@+id/button1"/>
</LinearLayout>
<FrameLayout
android:background="@color/blue"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
</RelativeLayout>
答案 5 :(得分:0)
所以是的....按钮似乎有一个名为stateListAnimator的属性。
所以你需要做的是为棒棒糖或更高版本制作另一个布局文件(v21)并在你的按钮xml中添加它:
android:stateListAnimator="@null"
对于较低版本的Android,它似乎是这样的:
android:stateListAnimator="@null"
tools:ignore="UnusedAttribute"
答案 6 :(得分:-2)
将此添加到您的Button标记:
<Button
...
android:background="@android:color/transparent" />