【问题标题】:I'm making weightSum but it can't be sorted我正在做 weightSum 但无法排序
【发布时间】:2014-09-07 02:01:44
【问题描述】:

我正在尝试对图像和文本进行排序,但它不起作用。

图片如下:

<LinearLayout
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:orientation="horizontal"
                  android:weightSum="100" >

          <ImageView
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:layout_weight="80"
                  android:gravity="right"
                  android:src="@drawable/image" />

          <Button
                  android:id="@+id/blah"
                  android:layout_width="fill_parent"
                  android:layout_weight="20"
                  android:gravity="left"
                  android:text="Blah blah blah blah"
                  android:textSize="15sp" />
</LinearLayout>

【问题讨论】:

  • 你想要什么?你现在的效果是什么?
  • 在我发布的网址上,棕色的图片在顶部有点高

标签: android xml eclipse


【解决方案1】:

添加

android:layout_gravity="center_vertical"

对于您的 ImageView 和您的 Button,这将为您提供您在图像中描绘的对齐方式。

<LinearLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:orientation="horizontal"
              android:weightSum="100" >

      <ImageView
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_gravity="center_vertical"
              android:layout_weight="80"
              android:gravity="right"
              android:src="@drawable/image" />

      <Button
              android:id="@+id/blah"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_gravity="center_vertical"
              android:layout_weight="20"
              android:gravity="left"
              android:text="Blah blah blah blah"
              android:textSize="15sp" />
</LinearLayout>

您也没有设置按钮的高度。

【讨论】:

    【解决方案2】:

    如果我得到了你想要达到的目标,你可以试试这个:

     android:id="@+id/blah"
     android:layout_width="fill_parent"
     android:layout_weight="20"
     android:gravity="left|center"
     android:text="Blah blah blah blah"
     android:textSize="15sp" />
    

    更改为gravity="left|center"

    【讨论】:

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