Jav*_*tor 2 java layout android android-linearlayout
我正在设计如下布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/messageText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Some really long text asd asd asd asd asd asd asd asd asd asd asd![enter image description here][1]" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="12:45 PM" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
它提供了如上所述的UI ...
哪个是我需要的完美.由于方向是水平的,因此不会将Button推离屏幕,因此长文本正在被正确包裹.按钮也没有伸展.
但如果文字很小.看起来像这样
我想要的是按钮应该像这样对齐到文本的左端
我知道,因为我把布局权重设为1.
在为按钮提供所需空间后,它会占用整个区域.
如果我不这样做.并使宽度成为包装内容.它适用于短文本.但随着文本的增长.
它将按钮推离屏幕.
那就是问题所在.希望我让我的问题足够描述.但当然很长时间阅读.痛苦当然.但是真的很高兴知道任何指针.
我也不愿意使用相对布局.
任何帮助将不胜感激.
谢谢
希望这对你有用.请试试这个:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/messageText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Some really long text asd asd asd asd asd asd asd asd asd asd asd![enter image description here][1]" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="12:45 PM" />
Run Code Online (Sandbox Code Playgroud)
我认为你需要将androidlay的layout :layout_width ="fill_parent"更改为android:layout_width ="wrap_content"
归档时间: |
|
查看次数: |
2022 次 |
最近记录: |