我想设计一个具有相对布局的android Activity 。垂直线上应有 3 个(或之后 4 个)元素。我已经尝试过了,但是 TextView 隐藏在 ListView 后面。
代码有什么问题,如果我想在文本和 ListView 或 ListView 和按钮之间插入第四个元素......就像图像一样,我应该如何更改它以及它应该是什么样子。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:paddingBottom="10dp"
android:layout_above="@+id/listview"
android:text="@string/info" />
<ListView
android:id="@+id/listview"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_above="@+id/button"
android:layout_marginBottom="10dp" />
<ImageButton
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:onClick="start"
android:src="@drawable/button1" />
</RelativeLayout>
最佳答案
尝试将ReltiveLayout
更改为LinearLayout
或将LinearLayout
放在RelativeLayout之外,其中orientation="vertical"
将 TextView
放在 RelativeLayout
之外。像这样的事情:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/info" />
<RelativeLayout
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="@+id/listview"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_above="@+id/button"
android:layout_marginBottom="10dp" />
<ImageButton
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:onClick="start"
android:src="@drawable/button1" />
</RelativeLayout>
</LinearLayout>
关于java - Android 应用相对布局,包含 2-3 个元素和一个底部按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29241972/