【问题标题】:Relative layout rendering incorrect (buttons are messed up)相对布局渲染不正确(按钮乱七八糟)
【发布时间】:2014-01-25 09:02:07
【问题描述】:

预期布局:

布局渲染:

布局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>

所有布局都保持正确的纵横比,但如图所示,标记有问题的按钮被弄乱了。

谁能告诉我我在哪里缺少布局元素,或者我认为我缺少一些基本的东西。

【问题讨论】:

    标签: android android-layout android-relativelayout


    【解决方案1】:

    我想通了。您必须使用 ImageView 而不是 Buttons。希望这可以帮助某人。最大的浪费时间。

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

    您也可以参考这里:wrap_content is not working in button height android

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-12
      • 1970-01-01
      • 1970-01-01
      • 2019-08-16
      • 1970-01-01
      • 1970-01-01
      • 2014-11-29
      • 1970-01-01
      相关资源
      最近更新 更多