【问题标题】:Some strange behavior of the UI?用户界面的一些奇怪行为?
【发布时间】:2011-10-13 07:10:45
【问题描述】:

这是我拥有的静态 xml:

<LinearLayout
    android:id="@+id/LinearLayout"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

    <RelativeLayout
        android:id="@+id/Header"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1.5"
        android:background="@drawable/header_bg"
        android:padding="0dp"
        >

        <ImageView
            android:id="@+id/hLogo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:src="@drawable/logo"
            />

        <TextView
            android:id="@+id/hActiveCategory"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="Today"
            android:textSize="18sp"
            android:textColor="#FFFFFF"
            />

        <Button
            android:id="@+id/hRefreshButton"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:drawableRight="@drawable/refresh"
            android:layout_alignParentRight="true"
            android:padding="0dp"
            />

    </RelativeLayout>

</LinearLayout>

发生了什么? - 当我尝试将 Buttonid=hRefreshButton 对齐到其父级的右侧(RelativeLayout id=Header)按钮和屏幕右边界之间仍有空间。为什么会这样?有什么建议?另外我必须强调我正在 AVD 模拟器上进行测试。

【问题讨论】:

    标签: android user-interface alignment


    【解决方案1】:

    您的按钮与父级(相对布局)对齐,但由于默认背景,您可能会看到按钮右侧留有一些空间。

    尝试将背景设置为某些图像或设置背景颜色,您将自己看到。

    沙士

    【讨论】:

    • 我试过了,还是不行。我也不认为这是问题所在,为什么我这么认为 - 如果你说的是真的,那么相对布局应该在其右边界和屏幕右边界之间具有相同的空间。我知道问题出在哪里,但不知道如何解决它,它在 Button 中,因为当我说android:background="@drawable/refresh" 时,已经没有这样的空间了。 UI 组件 Button 的一些默认属性导致了它。
    • 默认背景是这样的。由于您已经给出了包装内容,您将获得边框效果。基本上默认背景是按钮图片+透明填充。将背景设置为#00000000,您将看不到填充
    • 好的,如果是真的,为什么我没有在按钮顶部得到这个透明填充(实际上问题应该是 - 为什么它不在按钮周围)而且它就在左边。
    • 你的答案是正确的,但是有没有办法在不设置android:background 属性的情况下删除这个透明填充?
    • 那是因为 Button 视图的默认可绘制对象有右下边距。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-07
    • 2015-12-25
    • 1970-01-01
    • 2018-02-10
    • 1970-01-01
    • 2019-03-12
    相关资源
    最近更新 更多