Android中的RelativeLayout:Widget不显示

时间:2016-05-18 17:02:48

标签: android-layout

我在使用RelativeLayout时遇到了麻烦。我想在布局屏幕的底部显示一个按钮,但它没有显示。

见下图:

http://i.imgur.com/70XxIka.png

我的XML:

System.Data.Linq.SqlClient.Implementation.ObjectMaterializer<System.Data.SqlClient.SqlDataReader>.Convert<string>

我尝试了所有我知道的选项..我使用android:layout_below设置位置,现在它已隐藏。

1 个答案:

答案 0 :(得分:0)

列表视图的线性布局占用了android:layout_height="match_parent"的剩余房地产,因此按钮被推离屏幕。

要解决此问题,请按下按钮并将其放在相对布局父级的底部。然后在按钮顶部构建listview线性布局。像下面这样的东西。这可能不是你想要的,但它会让你大部分都在那里。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity">

<TextView
    android:id="@+id/textViewNovoSabor"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="SABORES EXISTENTES"
    android:textAlignment="center"
    android:textColor="#0501e5" />

<LinearLayout
    android:id="@+id/rowsContainerControleSabor"
    style="@android:style/Widget.Holo.Light.EditText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    <!-- This is the key idea along with placement of the button layout. -->
    android:layout_above="@+id/myButton"
    android:layout_below="@+id/textViewNovoSabor"
    android:layout_gravity="center_horizontal"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <ListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</LinearLayout>

<LinearLayout
    android:id="@id/myButton"
    android:layout_width="match_parent"
    android:layout_height="100dp"
    <!-- This is the key idea. -->
    android:layout_alignParentBottom="true"
    android:orientation="vertical">

    <Button
        android:id="@+id/btnAddNewItem"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/rowsContainerControleSabor"
        android:height="20dp"
        android:background="#FF0000"
        android:paddingLeft="5dp"
        android:text="Adicionar sabor"
        android:textColor="@android:color/darker_gray" />
</LinearLayout>

相关问题