UI 的一些奇怪行为?
这是我拥有的静态 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>
发生了什么? - 当我尝试将 Button 与 id=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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的按钮相对于父级(相对布局)右对齐,但由于默认背景,您可能会看到按钮右侧留有一些空间。
尝试将背景设置为某些图像或设置背景颜色,您会自己看到。
沙什
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