UI 的一些奇怪行为?

发布于 2024-11-26 09:19:09 字数 1741 浏览 3 评论 0原文

这是我拥有的静态 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 模拟器上进行测试。

This is the static xml that I have:

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

What is happening? - when I try to align Button with id=hRefreshButton to the Right of its parent (RelativeLayout with id=Header) there is still space between the button and the right bound of the screen. Why this is happening? Any suggestions? Also I have to emphasize that I'm testing on AVD emulator.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柠檬 2024-12-03 09:19:09

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

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

沙什

Your button is getting right aligned with respect to parent (Relative Layout) but because of the default background you may see some space left on the right side of the button.

Try setting the background to some image or set background color, you will see for yourself.

Shash

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文