【问题标题】:How to fill a row listview according to another listview inside it如何根据其中的另一个列表视图填充行列表视图
【发布时间】:2013-01-22 21:56:40
【问题描述】:

我有一个 ListView,每行都有一张照片,照片下方还有另一个 ListView,其中包含关于照片的 cmets。问题是子 ListView 只显示第一行,因为父 ListView 的大小。

有什么办法可以让父ListView的大小根据子ListView的大小灵活变通?

【问题讨论】:

  • 我不认为我们可以在一个活动中实现 2 个列表视图?不过,我不确定..我认为我们不能在单个活动中为 2 个列表视图设置高度。
  • 发布一些代码............

标签: android listview size height


【解决方案1】:

我的xml代码

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relLayoutMain"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="@layout/background" 
    >

    <ListView
        android:id="@+id/photoList"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:cacheColorHint="#00000000"
        android:footerDividersEnabled="true"
        android:paddingTop="5sp" >

    </ListView>     
</RelativeLayout>

photoList 的行布局为:

<?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="wrap_content" >

    <ImageView
       android:id="@+id/imgView"
       android:contentDescription="@string/app_name"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:paddingLeft="10dp"
       android:paddingRight="10dp"
       android:layout_below="@+id/llUserHeader"
       android:adjustViewBounds="true"
       />


    <ListView android:id="@+id/commentList"

        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:layout_below="@+id/imgView"   
        android:cacheColorHint="#00000000"
        android:footerDividersEnabled="true"
        >
    </ListView>

</RelativeLayout>

commentList 的行布局为:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content" 
   android:paddingLeft="10sp"
   android:paddingRight="10sp"
   android:paddingTop="5sp"
   android:orientation="horizontal"
   >
    <TextView
            android:id="@+id/usernamecomment"
            android:text="@string/share_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="15sp"
             />
    <TextView 
        android:id="@+id/comment"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_marginLeft="3sp"
        />
</LinearLayout>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-05
    • 1970-01-01
    • 1970-01-01
    • 2021-03-08
    • 2012-07-14
    • 1970-01-01
    相关资源
    最近更新 更多