Android 如何在按钮和ImageView之间垂直放置ListView
我正在尝试创建一个ListView,它适合按钮和ImageView。 我有一个RelativeLayout,它在顶部有一个按钮,在底部有一个ImageView。 我希望它们之间有一个列表视图。这就是我所做的 我在按钮下看到我的listView,但它与底部的ImageView重叠。 那么如何使ListView位于ImageView之上呢Android 如何在按钮和ImageView之间垂直放置ListView,android,Android,我正在尝试创建一个ListView,它适合按钮和ImageView。 我有一个RelativeLayout,它在顶部有一个按钮,在底部有一个ImageView。 我希望它们之间有一个列表视图。这就是我所做的 我在按钮下看到我的listView,但它与底部的ImageView重叠。 那么如何使ListView位于ImageView之上呢 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/control_panel"
android:layout_width="@dimen/mywidth"
android:layout_height="match_parent"
android:orientation="vertical">
<Button android:id="@+id/button"
android:layout_height="@dimen/button_size"
android:layout_width="@dimen/button_size"
android:scaleType="center"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="@drawable/btn_shutter" />
<ListView android:id="@+id/image_list"
android:layout_width="@dimen/button_size"
android:layout_height="wrap_content"
android:drawSelectorOnTop="false"
android:layout_above="@+id/image"
android:layout_below="@+id/button"/>
<ImageView
android:id="@+id/image"
android:layout_width="@dimen/mywidth"
android:layout_height="@dimen/image_height"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
您是否设置了相对位置?如果没有,可以使用带权重的线性布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/control_panel"
android:layout_width="@dimen/mywidth"
android:layout_height="match_parent"
android:orientation="vertical">
<Button android:id="@+id/button"
android:layout_height="0px"
android:layout_width="@dimen/button_size"
android:scaleType="center"
android:layout_weight="1"
/>
<ListView android:id="@+id/image_list"
android:layout_width="@dimen/button_size"
android:layout_height="0px"
android:drawSelectorOnTop="false"
android:layout_weight="6"/>
<ImageView
android:id="@+id/image"
android:layout_width="@dimen/mywidth"
android:layout_height="0px"
android:layout_weight="1"/>
您是否已设置为RelativeLayout?如果没有,可以使用带权重的线性布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/control_panel"
android:layout_width="@dimen/mywidth"
android:layout_height="match_parent"
android:orientation="vertical">
<Button android:id="@+id/button"
android:layout_height="0px"
android:layout_width="@dimen/button_size"
android:scaleType="center"
android:layout_weight="1"
/>
<ListView android:id="@+id/image_list"
android:layout_width="@dimen/button_size"
android:layout_height="0px"
android:drawSelectorOnTop="false"
android:layout_weight="6"/>
<ImageView
android:id="@+id/image"
android:layout_width="@dimen/mywidth"
android:layout_height="0px"
android:layout_weight="1"/>
试试这个
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/control_panel"
android:layout_width="@dimen/mywidth"
android:layout_height="match_parent"
android:orientation="vertical">
<Button android:id="@+id/button"
android:layout_height="@dimen/button_size"
android:layout_width="wrap_content"
android:layout_alignParentTop="true"
android:background="@drawable/btn_shutter" />
<ImageView
android:id="@+id/image"
android:layout_width="@dimen/mywidth"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
<ListView android:id="@+id/image_list"
android:layout_width="@dimen/button_size"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"
android:layout_above="@+id/image"
android:layout_below="@+id/button"/>
</RelativeLayout>
试试这个
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/control_panel"
android:layout_width="@dimen/mywidth"
android:layout_height="match_parent"
android:orientation="vertical">
<Button android:id="@+id/button"
android:layout_height="@dimen/button_size"
android:layout_width="wrap_content"
android:layout_alignParentTop="true"
android:background="@drawable/btn_shutter" />
<ImageView
android:id="@+id/image"
android:layout_width="@dimen/mywidth"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
<ListView android:id="@+id/image_list"
android:layout_width="@dimen/button_size"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"
android:layout_above="@+id/image"
android:layout_below="@+id/button"/>
</RelativeLayout>
如果不知道@dimen
变量的值,很难判断。请尝试计算按钮底部和ImageView顶部之间的距离,然后在运行时将其设置为ListView的高度。如果不知道@dimen
变量的值,很难判断。请尝试计算按钮底部和ImageView顶部之间的距离,然后在运行时将其设置为ListView的高度。为什么在ListView中使用android:layout_weight=“6”?值6的含义是什么?上面的布局和下面的布局在LinearLayout中仍然有效吗?哦,我的意思是删除上面的布局和下面的布局。我相应地修改了代码。布局_weight=“6”本质上是该元素应填充父视图的哪个部分的比率。如果按钮和图像的权重为1,则总数为8,使列表视图占据父线性布局的6/8。然后可以调整权重以满足您的需要。为什么在ListView中使用android:layout\u weight=“6”?值6的含义是什么?上面的布局和下面的布局在LinearLayout中仍然有效吗?哦,我的意思是删除上面的布局和下面的布局。我相应地修改了代码。布局_weight=“6”本质上是该元素应填充父视图的哪个部分的比率。如果按钮和图像的权重为1,则总数为8,使列表视图占据父线性布局的6/8。然后可以调整重量以满足您的需要。