【问题标题】:How to create a fixed/dynamic width column layout?如何创建固定/动态宽度的列布局?
【发布时间】:2012-10-30 00:29:59
【问题描述】:

我正在尝试构建一个与其父宽度匹配的视图(最好是线性布局)。这个布局应该有 2 个孩子(水平):

  1. 应该占用所有可用宽度的 TextView - 或至少包裹其内容(但在任何情况下都不会与其他视图重叠)。
  2. 另一个具有 60dp 固定宽度的 LinearLayout。

这是我想要实现的基本草图:

【问题讨论】:

    标签: android android-layout android-linearlayout android-view


    【解决方案1】:

    我最近回答了这个here。只需将答案中的第二个 TextView 与您的孩子 LinearLayout 交换即可

    【讨论】:

      【解决方案2】:

      这个怎么样:

      <?xml version="1.0" encoding="utf-8"?>
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="horizontal" >
          <TextView 
              android:layout_width="0dip"
              android:layout_height="fill_parent"
              android:background="#ff0000"
              android:gravity="center"
              android:text="TextView Multiline"
              android:textSize="10dp"
              android:textColor="#ffffff"
              android:layout_weight="1"/>
          <LinearLayout 
              android:layout_width="60dp"
              android:layout_height="fill_parent"
              android:gravity="center"
              android:background="#0000ff" >
              <TextView 
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:text="TextView"
                  android:textColor="#ffffff"
                  android:textSize="10dp"/>        
          </LinearLayout>
      </LinearLayout>
      

      虽然 60 dp 真的很窄,恕我直言

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-12-22
        • 2015-11-06
        • 1970-01-01
        • 2012-11-09
        • 2015-08-05
        相关资源
        最近更新 更多