Android布局:即使宽度/高度为0,重量也不起作用

时间:2013-02-15 21:55:25

标签: android android-layout

FrameLayout的layout_weight是0.13,但它看起来比它大得多。为什么?很多推荐都是android:layout_height =“0dp”,但它没有帮助。

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent" android:background="@drawable/background" android:weightSum="1">

    <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="0dp" android:background="@drawable/bar_background" android:layout_weight="0.13">
        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/header"
                android:id="@+id/textView" android:layout_gravity="center" android:textSize="@dimen/header_size"
                android:textColor="#ffffff" android:layout_marginTop="@dimen/header_margin_top" />
    </FrameLayout>
    <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        <EditText
                android:inputType="text"
                android:layout_width="match_parent"
                android:layout_height="48dp"
                android:id="@+id/textEdit"/>
        <ImageView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/imageView" android:layout_gravity="center" android:src="@drawable/separator"
                android:scaleType="fitXY"/>
        <ListView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/listView" android:layout_gravity="center" android:choiceMode="singleChoice"
                android:scrollingCache="false" android:cacheColorHint="#00000000"/>
    </LinearLayout>
</LinearLayout>

4 个答案:

答案 0 :(得分:2)

认为可能是因为FrameLayout的兄弟姐妹都没有体重。尝试在内部LinearLayout中添加一个权重(可能是.87),看看是否能解决问题。

答案 1 :(得分:1)

对不起,看起来像是IntelliJ IDEA的预览错误。一切都很好的设备。谢谢大家。

答案 2 :(得分:0)

我已经尝试过你的布局了,在为兄弟的LinearLayout设置了0.87的重量和0dp的layout_height后,它对我来说很好。也许您在FrameLayout中设置为内部TextView的尺寸太大了?

答案 3 :(得分:0)

android:textSize="@dimen/header_size"

我认为因为它太大所以它会迫使你的FrameLayout比它应该更大

相关问题