2015-07-01 51 views
0

我想开发功能类似这样的如何设置ListView的底端动态

enter image description here

当任何项目被添加,然后底部RelativeLayoutVISIBLE 如果未选择任何项目,那么它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> 

当没有项目被选中,那么底部RelativeLayoutGONE图像2

当任何项目被添加然后底部RelativeLayoutVISIBLE图3 3

+0

ü上启动,然后代码张贴代码 –

回答

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> 
1

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

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

将layout_above属性添加到列表中。在xml中,它必须位于底部布局下方,否则将不会声明您给该布局的标识(在我的示例中为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> 
+0

这是正确的答案 – Tomislav

0

放置RelativeLayout

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

0

首先,为您的内部相对布局给出一个id。

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

查找您的活动代码布局,使用:

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

然后,您可以用改变的可视性:

layout.setVisibility(RelativeLayout.VISIBLE);