【问题标题】:Listview with custom columns layout nested LinearLayouts具有自定义列布局嵌套 LinearLayouts 的 Listview
【发布时间】:2013-04-22 10:42:22
【问题描述】:

我正在尝试制作具有以下布局的餐厅菜单。 item 字段和 description 字段在 item 的右侧 price 金额。我已经尝试了所有方法,从对每一行使用列表视图以及将项目和描述设置为 2 项目布局的列表视图,但我在保持其他列表视图同步时遇到了问题。

现在我尝试将列表视图布局作为我的主要布局,并添加一个水平线性布局,其中添加了相同权重的文本视图。至于应该有 2 个项目的第一列,我使用了一个垂直线性布局并将文本视图添加到它

我想要的是将垂直线性布局权重设置为 3 并将其余项目设置为 1 。在垂直线性布局中,我想设置文本视图以填充但不超过其他其他列的宽度以及扭曲内容的高度,因为我正在从数据库中加载项目的描述,这是相当多的行。

到目前为止我尝试的是以下这只是添加到列表布局的行布局。下图显示了列表的问题。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="left|center"
    android:orientation="horizontal"
    android:paddingBottom="6dip"
    android:paddingTop="4dip" >

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/text1_"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:text="TextView" />

        <TextView
            android:id="@+id/text2_"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:text="TextView" />
    </LinearLayout>

     <TextView android:id="@+id/FROM_CELL"
         android:layout_width="0dip"
         android:layout_height="wrap_content" 
         android:layout_weight="1"/>

     <TextView android:id="@+id/TO_CELL"
         android:layout_width="0dip"
         android:layout_height="wrap_content"  
         android:layout_weight="1"/>

     <TextView
         android:id="@+id/TRAIN_CELL"
         android:layout_width="0dip"
         android:layout_height="wrap_content"
         android:layout_weight="1" />

</LinearLayout>

【问题讨论】:

    标签: android android-layout android-listview android-linearlayout


    【解决方案1】:

    使用这个布局

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical" >
    
            <TextView
                android:id="@+id/text1_"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:text="TextView" />
    
            <TextView
                android:id="@+id/text2_"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="TextView" />
        </LinearLayout>
    
         <TextView android:id="@+id/FROM_CELL"
             android:layout_width="0dip"
             android:layout_height="wrap_content" 
             android:layout_weight="1"
              />
    
         <TextView android:id="@+id/TO_CELL"
             android:layout_width="0dip"
             android:layout_height="wrap_content"  
             android:layout_weight="1"
            />
    
         <TextView
             android:id="@+id/TRAIN_CELL"
             android:layout_width="0dip"
             android:layout_height="wrap_content"
             android:layout_weight="1" 
             />
    
    </LinearLayout>
    

    【讨论】:

    • 修复了垂直线性布局但其他文本视图仍然混乱
    • 在垂直线性布局中设置文本视图的最小和最大宽度固定它的答案
    猜你喜欢
    • 2012-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多