【发布时间】:2018-04-07 13:25:30
【问题描述】:
我正在尝试设计这样的布局:
目前,我有 2 个布局文件。一种是activity_main.xml,它只有listview。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayoutxmlns: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="com.example.xcrix.taskmanager.MainActivity">
<ListView
android:id="@+id/tasks"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="235dp" />
</RelativeLayout>
另一个是 row.xml,我正在使用它与 arrayadapter 一起显示数据。
<?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">
<Button
android:id="@+id/btnDelete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="27dp"
android:layout_marginRight="27dp"
android:onClick="deleteTask"
android:text="Delete" />
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btnDelete"
android:layout_alignBottom="@+id/btnDelete"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:text="Name" />
<TextView
android:id="@+id/desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/name"
android:layout_marginLeft="28dp"
android:layout_marginStart="28dp"
android:layout_toEndOf="@+id/name"
android:layout_toRightOf="@+id/name"
android:text="Desc" />
<TextView
android:id="@+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/desc"
android:layout_alignBottom="@+id/desc"
android:layout_centerHorizontal="true"
android:text="Date" />
</RelativeLayout>
当我尝试向 activity_main.xml 添加新元素时,由于某种原因,我无法按照我的意愿对齐它们。
这是它的外观:
【问题讨论】:
-
尝试将row.xml中相对布局的宽度和高度更改为wrap_content
-
你真正想做的,因为你的布局只显示列表视图,如果你想要单独的视图,然后手动将它们添加到列表视图以固定高度滚动的布局
标签: android android-layout listview