【问题标题】:how to make tablelayout with same width row, in one row contains two cell with same height如何制作具有相同宽度行的表格布局,在一行中包含两个具有相同高度的单元格
【发布时间】:2015-07-30 22:35:55
【问题描述】:

如何为下图制作android布局?但我希望每一列都有相同的宽度

我已创建,但每列的宽度不能相同

<LinearLayout
    android:orientation="horizontal" 
    android:layout_width="fill_parent"
    android:weightSum="2" 
    android:layout_height="fill_parent">
    <TableLayout 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="#9812AC">        
        <TableRow>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="100dip"
                android:text="Happy Vendor3">
            </TextView>
        </TableRow>
    </TableLayout>
    <TableLayout 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_weight="1">        
        <TableRow>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="50dip"
                android:text="Happy Vendor"
                android:background="#000">
            </TextView>
        </TableRow>
        <TableRow>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="50dip"
                android:text="Happy Vendor2"
                android:background="#CCC">
            </TextView>
        </TableRow>
    </TableLayout>
</LinearLayout>

我只是尝试使用 textview 来简化它。提前致谢。

【问题讨论】:

    标签: android android-linearlayout tablelayout


    【解决方案1】:
    <TableRow 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    
    <ImageView
    android:src="@drawable/someimage1" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight=".5"/>
    
    <LinearLayout
    android:orientation="vertical" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight=".5">
    
    <ImageView
    android:src="@drawable/someimage2"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight=".5"/>
    
    <ImageView
    android:src="@drawable/someimage3"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight=".5"/>
    
    </LinearLayout>
    </TableRow>
    

    【讨论】:

    • 它不起作用,所有的imageview都会像垂直方向的线性布局一样显示
    • 是的,它有效,你能不能也给我autoresize imageview?注意我使用你的布局
    • “自动调整图像视图”?如果您的意思是图像视图扩展到视图的最大范围,它是 android:scaleType="fitXY" 或 android:scaleType="fitCenter"
    【解决方案2】:

    试试这个

    <LinearLayout
            android:orientation="horizontal"
            android:weightSum="3"
            android:layout_width="match_parent"
            android:layout_height="250dp">
    
            <ImageView
                android:layout_width="wrap_content"
                android:layout_weight="2"
                android:background="@color/red"
                android:layout_height="match_parent"
                android:id="@+id/imageView" />
    
            <LinearLayout
                android:orientation="vertical"
                android:layout_weight="1"
                android:weightSum="2"
                android:layout_width="0dp"
                android:layout_height="match_parent">
                <ImageView
                    android:layout_width="match_parent"
                    android:layout_weight="1"
                    android:background="@color/black"
                    android:layout_height="0dp"
                    android:id="@+id/imageView2" />
                <ImageView
                    android:layout_width="match_parent"
                    android:layout_weight="1"
                    android:background="@color/blue"
                    android:layout_height="0dp"
                    android:id="@+id/imageView3" />
            </LinearLayout>
        </LinearLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多