首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >android layout_weight将视图挤压得太薄

android layout_weight将视图挤压得太薄
EN

Stack Overflow用户
提问于 2013-05-14 22:36:05
回答 4查看 392关注 0票数 0

我似乎想不出如何有效地使用安卓的layout_weight属性。我正在尝试创建一个有三个文本视图的自定义listView。主要的textView位于左上角,然后我有一个位于右上角的文本视图,然后第三个位于主要textView的下面。我希望主要的和右上角的两个在某个水平轴上,但是我希望主要的textView占据大约70%的宽度,而另一个textView占据剩余的30%。无论我为主textView和右textView分配多大的权重,主textView总是更大,并且将正确的数据textView挤得太细。

我的代码:

代码语言:javascript
运行
复制
<LinearLayout android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:orientation="horizontal"
              android:padding="5dip"
              android:id="@+id/Llayout">
<!-- Title-->
<TextView
        android:id="@+id/primaryTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Loading some tadglkj dgjg sadlgkj dgksgj sgj sdgk"
        android:textColor="#040404"
        android:typeface="sans"
        android:textSize="18dip"
        android:textStyle="bold"
        android:paddingTop="0dp"
        android:background="#888"
        android:layout_weight="4"/>

<!-- Right Data -->
<TextView
        android:id="@+id/rightData"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="10"
        android:layout_marginRight="5dip"
        android:textSize="12dip"
        android:textColor="#B53021"
        android:textStyle="bold"
        android:background="#bada55"
        android:text="1.3 mi"/>
</LinearLayout>

<!-- Secondary title -->
<TextView
        android:id="@+id/secondaryTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#343434"
        android:textSize="12dip"
        android:layout_marginTop="1dip"
        android:text="hello this is some other data"/>

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2013-05-14 22:56:02

我需要做几件事。

  1. 将weightSum分配给包含TextViews
  2. 的LinearLayout然后我需要将TextViews的TextViews更改为"0dp“而不是"wrap_content"
票数 0
EN

Stack Overflow用户

发布于 2013-05-14 22:39:22

在你想要达到70%的项目上设置layout_weight="30",在你想要达到30%的项目上设置layout_weight="70"。这将有望解决您的问题。

票数 0
EN

Stack Overflow用户

发布于 2013-05-14 22:42:31

你需要在你的容器中定义一个权重和。在您的示例中,如下所示(仅包含所需的相关属性):

代码语言:javascript
运行
复制
<LinearLayout 
      android:weightSum="1">
<!-- Title-->
<TextView
     android:layout_weight=".7"/>

<!-- Right Data -->
<TextView
       android:layout_weight=".3"/>
</LinearLayout>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16546053

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档