Java Android应用程序布局
我正在为2.2版本开发一个android应用程序 我的应用程序必须具有以下结构:Java Android应用程序布局,java,android,layout,Java,Android,Layout,我正在为2.2版本开发一个android应用程序 我的应用程序必须具有以下结构: [此处旋转器(固定高度)] [列表视图(非固定高度)] [图像视图(固定高度)] 我只能使用纵向 我使用线性布局。如何计算listView高度以在屏幕顶部显示微调器,在底部显示imageview,并且listView覆盖所有可用空间,但不将其他视图推离视野 这将是很酷的,使其dinamic的许多屏幕分辨率 谢谢您需要在“可变高度”项目上使用android:layout\u weight属性,以便它填充可用空间 &l
[此处旋转器(固定高度)]
[列表视图(非固定高度)]
[图像视图(固定高度)]
我只能使用纵向
我使用线性布局。如何计算listView高度以在屏幕顶部显示微调器,在底部显示imageview,并且listView覆盖所有可用空间,但不将其他视图推离视野
这将是很酷的,使其dinamic的许多屏幕分辨率
谢谢您需要在“可变高度”项目上使用android:layout\u weight属性,以便它填充可用空间
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Spinner
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
使用相对布局来完成您需要的内容
<?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" >
<Spinner
android:id="@+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:src="@drawable/icon" />
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/spinner1"
android:layout_above="@+id/imageView1" />
</RelativeLayout>
通过执行此操作,listview将调整其大小,使其适合屏幕上的微调器和imageview这里是另一种方法,使用
权重
。这可能是最简单的方法
您可以在重量中输入希望屏幕占据的百分比
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Spinner
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="10"/>
<ListView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="80"></ListView>
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="10"/>
</LinearLayout>
编辑:
现在我考虑一下,这将“修复”所有小部件的大小。它们将“固定”在屏幕的百分比上。这将与其他屏幕尺寸进行很好的缩放,但您确实说过希望不固定ListView
。在本例中,ListView
是否仍覆盖图像?好像是的。试试看,你会明白的。布局使用布局权重,该权重指定视图之间的相对比率。0表示固定大小,任何较大的值(例如我使用的1)都允许拉伸。因此,如果第一个和第三个视图是固定大小的,请在其高度上使用wrap_内容,或设置明确的高度,例如,30dpI只是检查它,没有在布局中放置任何内容,它正在覆盖,但我将尝试在布局中添加内容并查看。