如何动态设置Listview底端

时间:2015-07-01 13:22:42

标签: android android-layout

我想开发像这样的功能

enter image description here

添加任何项目后,class MyService { public function __construct($config) {} } RelativeLayout VISIBLE 如果没有选择任何项目,则GONE

问题: 我有这样的问题: enter image description here

图片1: 代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginTop="50dp"
    android:background="@android:color/white" >

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"  >
    </ListView>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true" >

        <View
            android:id="@+id/sprator"
            android:layout_width="match_parent"
            android:layout_height="2dp"
            android:background="@android:color/black" />

        <ImageView
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:layout_margin="10dp"
            android:src="@drawable/icon" />

        <ImageView
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:layout_alignParentRight="true"
            android:layout_margin="10dp"
            android:src="@drawable/icon" />
    </RelativeLayout>

</RelativeLayout>

如果没有选择任何项目,那么RelativeLayout底部GONE图片2

添加任何项目后,RelativeLayout底部VISIBLE图片3

5 个答案:

答案 0 :(得分:2)

将layout_above属性添加到列表中。在xml中,它必须低于底部布局,否则你没有声明你给那个布局的id(在我的例子中是resultLayout)。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="50dp"
android:background="@android:color/white" >

<RelativeLayout
    android:id="@+id/confirmLayout"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_alignParentBottom="true" >

    <View
        android:id="@+id/sprator"
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:background="@android:color/black" />

    <ImageView
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_margin="10dp"
        android:src="@drawable/icon" />

    <ImageView
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_alignParentRight="true"
        android:layout_margin="10dp"
        android:src="@drawable/icon" />
</RelativeLayout>

<ListView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@id/confirmLayout"  >
</ListView>
</RelativeLayout>

答案 1 :(得分:1)

将其更改为LinearLayout,如下面的伪XML:

<LinearLayout>
   <ListView layout_weight="1" layout_height="0dp" />
   <RelativeLayout layout_height="wrap_content" /> // bottom layout
</LinearLayout>

答案 2 :(得分:1)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    android:orientation="vertical" >
    <ListView
        android:id="@+id/productList"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />
    <RelativeLayout
        android:id="@+id/relLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:visibility="gone"
        android:layout_alignParentBottom="true" >
        <View
            android:id="@+id/sprator"
            android:layout_width="match_parent"
            android:layout_height="2dp"
            android:background="@android:color/black" />
        <ImageView
            android:id="@+id/icoShopping"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:layout_margin="10dp"
            android:src="@drawable/icon" />

        <ImageView
            android:id="@+id/icoCheckout"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:layout_alignParentRight="true"
            android:layout_margin="10dp"
            android:src="@drawable/icon" />
    </RelativeLayout>
</LinearLayout>

答案 3 :(得分:0)

ListView放在RelativeLayout

上方

在您的活动中实施OnItemClickListener。然后,当用户选择ro取消选择项目时,将RelativeLayout的可见性更改为View.VSIBLEView.GONE

答案 4 :(得分:0)

首先,给你的内部相对布局一个id。

然后,使用setOnItemClickListener捕获点击事件。

使用以下命令查找活动代码中的布局:

RelativeLayout layout = (RelativeLayout)findViewById(R.id.your_id);

然后您可以使用以下方式更改可见性:

layout.setVisibility(RelativeLayout.VISIBLE);