【问题标题】:Android Java Justified tablerow in linear layout线性布局中的Android Java Justified tablerow
【发布时间】:2014-12-04 02:56:10
【问题描述】:

我有一个线性布局的表格行 表格行设置为填充父级 我在tablerow中有三个对象,一个textview,一个editbox,一个buttong 他们都水平排列

我希望左侧的 textview 固定为 100p 宽度 我希望右边的按钮固定在 50dp 宽度

如何将编辑框设置在中间,以便所有三个都填充屏幕的宽度,这可能因设备而异

我尝试了各种匹配和换行的组合,但似乎无法得到它

任何想法

标记

【问题讨论】:

    标签: java android layout android-linearlayout tablerow


    【解决方案1】:

    您必须为视图组的特定子项使用 layout_weight 或使用 relativelayout 可能会解决您的问题,请发布您的布局 XML。

    【讨论】:

      【解决方案2】:

      尝试以下操作,使用layout_weight

      <LinearLayout
          android:orientation="horizontal"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          xmlns:android="http://schemas.android.com/apk/res/android">
      
          <TextView
              android:layout_width="100dp"
              android:layout_height="wrap_content"
              android:textAppearance="?android:attr/textAppearanceMedium"
              android:text="Name"
              android:id="@+id/textView" />
      
          <EditText
              android:layout_width="0dp"
              android:layout_height="wrap_content"
              android:id="@+id/editText"
              android:layout_weight="1" />
      
          <Button
              android:layout_width="50dp"
              android:layout_height="wrap_content"
              android:text="Ok"
              android:id="@+id/button" />
      </LinearLayout>
      

      【讨论】:

        【解决方案3】:

        这时布局权重就派上用场了。

        • 对于固定元素,只需像往常一样分配width & height
        • 对于弹性的,将“0dp”设置为您想要弹性的尺寸,并在权重字段中输入weightlinearlayout 的布局参数)。李>

        哪个weight

        如果你只有一个弹性元件,没关系。如果您有 2 个,则可用空间将在权重之间按比例分配。因此,如果您想要 2 个弹性元件,其中一个是另一个的两倍,您需要分配权重 1 和 2。

        顺便说一句,不鼓励大量使用LinearLayoutsweight,因为Android 需要两倍的时间来计算它们的大小。如果您的表格有很多行,您肯定会注意到它不如固定元素快。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2014-10-11
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-11-21
          • 2013-05-19
          • 1970-01-01
          相关资源
          最近更新 更多