无法获得适当的布局和QUOT; FILL_PARENT" [英] Can't get proper layout with "fill_parent"
问题描述
我试图创建Android的这个简单的布局。
I'm trying to create this simple layout in Android.
A 应该换到适合其内容和离开|。center_vertical
对齐
A should wrap to fit its content and left|center_vertical
align.
B 应扩大尽可能,填补所有空白区域。
B should expand as much as possible, filling all empty space.
C 应该是右对齐,包装,以填补其内容,并且还对准 center_vertical
。
C should be right-aligned, wrapping to fill its content and also being aligned center_vertical
.
下面是我的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:gravity="left|center_vertical">
<!-- A -->
<ImageView android:id="@+id/example_item_icon"
android:layout_width="48px"
android:layout_height="48px"/>
<!-- B -->
<LinearLayout android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="left|center_vertical"
android:padding="5px">
<TextView android:id="@+id/example_item_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"/>
<TextView android:id="@+id/example_item_level_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold|italic"
android:lines="1"
android:textSize="10px"/>
</LinearLayout>
<!-- C -->
<TextView android:id="@+id/example_item_count_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="14px"/>
</LinearLayout>
在此布局的 C 推离屏幕。我怎样才能让这个布局工作?
In this layout, C is pushed off-screen. How can I make this layout work?
推荐答案
FILL_PARENT意思是被大如父,而不是用剩余的空白。相反FILL_PARENT的,只是采用Android:layout_width =0dip和android:layout_weight =1
fill_parent means "be as big as the parent," not "use the remaining empty space." Instead of fill_parent, just use android:layout_width="0dip" and android:layout_weight="1".
这篇关于无法获得适当的布局和QUOT; FILL_PARENT&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!