2016-02-10 50 views
0

这里是我的布局,我有一个带有两个RelativeLayouts的LinearLayout。一个充满TextView,另一个有ListView。现在,我手动设置高度,我想要做的是让RelativeLayout和TextViews确定高度。但是如果我使用Wrap Content,那么ListView希望和屏幕一样大。我怎样才能做到这一点?当内部有一个ListView时将内容包装在一个布局中

<?xml version="1.0" encoding="utf-8"?> 
<io.codetail.widget.RevealFrameLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_gravity="bottom" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <LinearLayout 
     android:id="@+id/product_info" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:weightSum="1" 
     android:orientation="horizontal" 
     android:baselineAligned="false"> 

     <RelativeLayout 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.71" 
      android:alpha="0.85" 
      android:background="@drawable/product_info_top_border"> 

      <TextView 
       android:id="@+id/product_info_name" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="16dp" 
       android:layout_marginLeft="16dp" 
       android:layout_marginRight="16dp" 
       android:layout_marginBottom="6dp" 
       android:textColor="@android:color/white" 
       android:text="@string/product_info_name" 
       android:textSize="16dp" 
       android:maxLines="2" 
       android:ellipsize="end" 
       android:textStyle="bold"/> 

      <TextView 
       android:id="@+id/product_info_shop" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginBottom="14dp" 
       android:maxLines="2" 
       android:ellipsize="end" 
       android:text="@string/footer_shop" 
       android:textSize="16dp" 
       android:textColor="@android:color/white" 
       android:layout_below="@+id/product_info_name" 
       android:layout_alignLeft="@+id/product_info_name" 
       android:layout_alignStart="@+id/product_info_name"/> 

      <TextView 
       android:id="@+id/product_info_description" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textColor="@android:color/white" 
       android:textSize="12dp" 
       android:text="@string/product_info_description" 
       android:maxLines="6" 
       android:ellipsize="end" 
       android:layout_marginRight="16dp" 
       android:layout_below="@+id/product_info_shop" 
       android:layout_alignLeft="@+id/product_info_shop" 
       android:layout_alignStart="@+id/product_info_shop"/> 

      <TextView 
       android:id="@+id/product_info_reference" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textColor="@android:color/white" 
       android:layout_marginTop="12dp" 
       android:text="@string/product_info_reference" 
       android:singleLine="true" 
       android:ellipsize="end" 
       android:layout_below="@+id/product_info_description" 
       android:layout_alignLeft="@+id/product_info_description" 
       android:layout_alignStart="@+id/product_info_description" /> 

      <TextView 
       android:id="@+id/product_info_price" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textColor="@android:color/white" 
       android:text="@string/product_info_price" 
       android:textSize="24dp" 
       android:paddingBottom="2dp" 
       android:paddingLeft="4dp" 
       android:paddingRight="5dp" 
       android:background="@drawable/product_price_footer_relief" 
       android:layout_marginBottom="14dp" 
       android:layout_alignParentBottom="true" 
       android:layout_alignLeft="@+id/product_info_description" 
       android:layout_alignStart="@+id/product_info_description"/> 

     </RelativeLayout> 

     <LinearLayout 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="0.29" 
      android:alpha="0.85" 
      android:background="@drawable/icon_list_left_border"> 

      <ListView 
       android:id="@+id/product_info_list_colors" 
       android:layout_marginTop="48dp" 
       android:layout_marginBottom="16dp" 
       android:layout_marginLeft="2dp" 
       android:layout_marginRight="2dp" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:scrollbars="vertical" 
       android:smoothScrollbar="true" 
       android:cacheColorHint="#00000000" 
       android:divider="@android:color/transparent" 
       android:dividerHeight="20dp"> 

      </ListView> 

     </LinearLayout> 

    </LinearLayout> 

</io.codetail.widget.RevealFrameLayout> 

编辑:我想摆脱这样的:

android:layout_height="275dp" 

所以高度由全TextViews(而不是ListView控件)

EDIT2的RelativeLayouts确定:更新代码

+0

请出示截图你想要什么 –

回答

0

您可以使用像这样的权重:

包装元件具有: 机器人:layout_hight = “WRAP_CONTENT”

第一个元素: 机器人:layout_hight = “WRAP_CONTENT”

第二元件具有: 机器人:layout_height = “match_parent”

<?xml version="1.0" encoding="utf-8"?> 
    <FrameLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_gravity="bottom" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <LinearLayout 
      android:id="@+id/product_info" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:weightSum="1" 
      android:orientation="horizontal" 
      android:baselineAligned="false"> 

      <LinearLayout 
       android:orientation="vertical" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="0.71" 
       android:alpha="0.85" 
       android:background="@color/colorPrimary"> 

       <TextView 
        android:id="@+id/product_info_name" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="16dp" 
        android:layout_marginLeft="16dp" 
        android:layout_marginRight="16dp" 
        android:layout_marginBottom="6dp" 
        android:textColor="@android:color/white" 
        android:text="product_info_name" 
        android:textSize="16dp" 
        android:maxLines="2" 
        android:ellipsize="end" 
        android:textStyle="bold"/> 

       <TextView 
        android:id="@+id/product_info_name1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="16dp" 
        android:layout_marginLeft="16dp" 
        android:layout_marginRight="16dp" 
        android:layout_marginBottom="6dp" 
        android:textColor="@android:color/white" 
        android:text="product_info_name" 
        android:textSize="16dp" 
        android:maxLines="2" 
        android:ellipsize="end" 
        android:textStyle="bold"/> 

       <TextView 
        android:id="@+id/product_info_name2" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="16dp" 
        android:layout_marginLeft="16dp" 
        android:layout_marginRight="16dp" 
        android:layout_marginBottom="6dp" 
        android:textColor="@android:color/white" 
        android:text="product_info_name" 
        android:textSize="16dp" 
        android:maxLines="2" 
        android:ellipsize="end" 
        android:textStyle="bold"/> 
       <TextView 
        android:id="@+id/product_info_name3" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="16dp" 
        android:layout_marginLeft="16dp" 
        android:layout_marginRight="16dp" 
        android:layout_marginBottom="6dp" 
        android:textColor="@android:color/white" 
        android:text="product_info_name" 
        android:textSize="16dp" 
        android:maxLines="2" 
        android:ellipsize="end" 
        android:textStyle="bold"/> 
      </LinearLayout> 

      <LinearLayout 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="0.29" 
       android:alpha="0.85" 
       android:background="@color/colorPrimaryDark"> 

       <ListView 
        android:id="@+id/product_info_list_colors" 
        android:layout_marginTop="48dp" 
        android:layout_marginBottom="16dp" 
        android:layout_marginLeft="2dp" 
        android:layout_marginRight="2dp" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:scrollbars="vertical" 
        android:smoothScrollbar="true" 
        android:cacheColorHint="#00000000" 
        android:divider="@android:color/transparent" 
        android:dividerHeight="20dp"> 

       </ListView> 

      </LinearLayout> 

     </LinearLayout> 

    </FrameLayout> 

enter image description here

+0

待办事项ÿ ou是指高度而不是宽度? – cuoka

+0

在这里,我重新发布 – TacoEater

+0

这对我来说并不奏效,它采用这种方法需要所有屏幕 – cuoka

相关问题