在android中将一个元素放在线性布局的右侧
我想将图像放置在视图的右侧。为此,我试图使用类似
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
...some other elements
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<ImageView
android:id="@+id/imageIcon"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:src="@drawable/image_icon" >
</ImageView>
</LinearLayout>
...
</RelativeLayout>
上面的内容似乎将图像放在中心的某个位置。无论我们处于纵向还是横向模式,如何确保图像右对齐?
谢谢!
I want to place an image to the right of the view. For that I am tyring to use something like
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
...some other elements
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<ImageView
android:id="@+id/imageIcon"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:src="@drawable/image_icon" >
</ImageView>
</LinearLayout>
...
</RelativeLayout>
The above seems to put the image somewhere in the center. How do I ensure that the image is right aligned regardless of whether we are in portrait or landscape mode?
Thanx!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
以下似乎有效。两个变化
1.按照Zortkun的建议使用orientation=vertical
2.在layout_width中使用wrap_content。
Following seems to work. Two changes
1. use orientation = vertical as suggested by Zortkun
2. Use wrap_content in layout_width.
如果您仅使用 Linearlayout 中的一个视图,则不需要 Linearlayout。
无论如何它在这里,
You don't need a Linearlayout if you use only one view inside the Linearlayout.
Anyway its here,
LinearLayout
的默认方向是水平的。确保线性布局的方向设置为垂直,否则您无法水平排列内容。The default orientation of
LinearLayout
is horizontal. Make sure the Linear layout's orientation is set to Vertical ortherwise you cannot aling stuff horizontally.