相对布局呈现不正确(按钮搞乱)

时间:2014-01-25 09:02:08

标签: android android-layout relativelayout

预期布局: enter image description here

呈现的布局: enter image description here

布局xml源:

<?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"
    >
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >
        <Button
            android:id="@+id/back"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:background="@drawable/banner_back"
        />
        <ImageView
            android:id="@+id/movie"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/back"
            android:background="@drawable/banner_background"
        />
        <ImageView android:id="@+id/midban"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/back"
            android:background="@drawable/banner_mid"
        />
        <Button
            android:id="@+id/share"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:background="@drawable/banner_right"
        />
        <Button
            android:id="@+id/fb"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/share"
            android:layout_alignParentRight="true"
            android:background="@drawable/banner_fb"
        />
        <Button
            android:id="@+id/dummyright"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_below="@+id/fb"
            android:background="@drawable/layoutslices_new_10"
        />
        <Button
            android:id="@+id/buy"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/fb"
            android:layout_toLeftOf="@+id/dummyright"
            android:background="@drawable/layoutslices_new_09"
        />
        <Button
            android:id="@+id/rt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/buy"
            android:layout_toLeftOf="@+id/dummyright"
            android:background="@drawable/layoutslices_new_11"
        />
        <Button
            android:id="@+id/imdb"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/rt"
            android:layout_toLeftOf="@+id/dummyright"
            android:background="@drawable/layoutslices_new_12"
        />
    </RelativeLayout>
</LinearLayout>

正在为所有布局保持正确的宽高比,但标有故障的按钮会混乱,如图所示。

有人能告诉我在哪里错过了布局元素,或者我相信我错过了一些基本的东西。

1 个答案:

答案 0 :(得分:0)

我发现了。您必须使用ImageView而不是Buttons。希望这有助于某人。最浪费时间。

即使使用换行内容和setbackground图像,也不能低于某个高度的按钮。如果图像的高度低于默认值,它会将图像缩放到默认高度。我不确定这是一个错误还是这是预期的行为。

您也可以在此处参考:wrap_content is not working in button height android

相关问题