我有以下布局(它很复杂,但我必须把它全部);我有3个LinearLayouts,以平铺的png作为背景水平放置:2必须放置在屏幕的顶部,最后放置在屏幕的底部。之间我必须把一个小部件画廊。LinearLayout和平铺背景的Android调整大小问题
我希望3个LinearLayouts获取用于其背景的png的高度(对于第一个而言是可以的,但对于调整大小的最后不是这样),并且该库采用屏幕的剩余大小。
我不明白为什么第三个LinearLayout被调整大小。
非常感谢您的帮助。我在代码后面放了2张图片以了解情况。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<!-- THE FOLLOWING LAYOUT SHALL TAKE THE HEIGHT OF THE IMAGE USED FOR BACKGROUND
=> IT IS OK -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@drawable/bg_title"
android:gravity="center_horizontal">
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/home_title"
android:textColor="@color/white"
android:gravity="center"
android:textSize="20sp"/>
</LinearLayout>
<!-- THE FOLLOWING LAYOUT SHALL TAKE THE HEIGHT OF THE IMAGE USED FOR BACKGROUND
=> IT IS OK -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@drawable/bg_channel_title">
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/channels_frameLayout">
<HorizontalScrollView
android:id="@+id/channel_scrollView"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/channel_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
</LinearLayout>
</HorizontalScrollView>
</FrameLayout>
</LinearLayout>
<!-- THE FOLLOWING LAYOUT SHALL TAKE THE REMAINING HEIGHT OF THE SCREEN -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
android:id="@+id/description_frameLayout">
<Gallery xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gallery"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
/>
</LinearLayout>
<!-- THE FOLLOWING LAYOUT SHALL BE PLACED ON THE BOTTOM OF THE SCREEN
AND TAKE THE HEIGHT OF THE IMAGE USED FOR BACKGROUND
=> IT IS NOK, THE LAYOUT IS RESIZED IN HEIGHT -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@drawable/bg_description"
android:id="@+id/description_layout"
android:gravity="bottom">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="left"
android:id="@+id/texts">
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/orange"/>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="right"
android:id="@+id/btns">
<ImageButton
android:id="@+id/info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:src="@drawable/btn_info" />
<ImageButton
android:id="@+id/favorite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:src="@drawable/btn_favorite" />
</LinearLayout>
</LinearLayout>
不幸的绘制具有正确的尺寸。我删除了所有其他布局,只保留包含按钮的布局。问题仍然存在,它调整大小。 – obo
如果删除背景可绘制,它是否调整为按钮大小? – Khetzal
我刚刚回答了我自己的问题,更准确地解释了我发现的问题和解决方案。 – obo