设置的LinearLayout一个最大宽度 [英] Setting a max width for LinearLayout
本文介绍了设置的LinearLayout一个最大宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何设置的最大宽度我水平的LinearLayout
?因此,如果内容是短(例如,一些文本),则布局收缩,并且如果内容是长,也不会扩大比一些最大宽度值更
How can I set the max width of my horizontal LinearLayout
? So if the contents are short (say, some text), the layout shrinks and if the contents are longer, it will not expand more than some max width value.
我preFER在XML级别这样做。
I prefer doing this at the XML level.
推荐答案
这做它 - 我需要什么超出了在之前建议回答是添加另一个布局( @ + ID / TheLayout
)的内容和布局顶部之间的包装:
This does it - what I needed beyond what was suggested in prior answer is to add another layout (@+id/TheLayout
) as a wrapper between the content and the top layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="100dip"
android:paddingRight="100dip">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/TheLayout"
android:layout_gravity="right">
<TextView android:id="@+id/TextView01"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1"
android:text="this is my text."
android:layout_gravity="center_vertical">
</TextView>
<ImageView android:id="@+id/ImageView01"
android:layout_height="wrap_content"
android:background="@drawable/icon"
android:layout_width="fill_parent">
</ImageView>
</LinearLayout>
</LinearLayout>
这篇关于设置的LinearLayout一个最大宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文