在相对布局中设置按钮
我遇到了以下问题:
我有一个以这种方式在横向模式下设置的活动:
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
这是我的 xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal">
<RelativeLayout android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="@+id/first"
android:orientation="vertical"
android:layout_weight="1.0">
<SurfaceView android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="@+id/surface_camera" />
</RelativeLayout>
<RelativeLayout android:layout_width="180dp"
android:layout_height="fill_parent"
>
<Button android:layout_width="fill_parent"
android:layout_height="320dip"
android:id="@+id/btnPhoto"
android:text="Take Photo"
android:layout_gravity="bottom|left" />
</RelativeLayout>
</RelativeLayout>
这是结果看起来像:
http://i56.tinypic.com/21103ld.png
我想要的是待设置按钮在屏幕底部(!从我的角度来看
)。
但我不知道如何实现这一点。
谢谢编辑1:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
>
<SurfaceView android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="@+id/surface_camera" />
<RelativeLayout android:layout_width="180dp"
android:layout_height="fill_parent"
>
<Button android:layout_width="fill_parent"
android:layout_height="320dip"
android:id="@+id/btnPhoto"
android:layout_alignParentBottom="true"
android:text="Take Photo"
android:layout_gravity="bottom|left" />
</RelativeLayout>
</RelativeLayout>
解决方案:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
>
<SurfaceView android:layout_width="450dip"
android:layout_height="fill_parent" android:id="@+id/surface_camera" />
<RelativeLayout android:layout_width="180dp"
android:layout_toRightOf="@id/surface_camera"
android:layout_height="fill_parent"
>
<Button android:layout_width="fill_parent"
android:layout_height="320dip"
android:id="@+id/btnPhoto"
android:layout_alignParentBottom="true"
android:text="Take Photo"
android:layout_gravity="bottom|right" />
</RelativeLayout>
</RelativeLayout>
I run into the following issue:
I have an activity which is set up in the landscape mode
in this way:
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
And here is my xml
file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal">
<RelativeLayout android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="@+id/first"
android:orientation="vertical"
android:layout_weight="1.0">
<SurfaceView android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="@+id/surface_camera" />
</RelativeLayout>
<RelativeLayout android:layout_width="180dp"
android:layout_height="fill_parent"
>
<Button android:layout_width="fill_parent"
android:layout_height="320dip"
android:id="@+id/btnPhoto"
android:text="Take Photo"
android:layout_gravity="bottom|left" />
</RelativeLayout>
</RelativeLayout>
And here is how the result looks like:
http://i56.tinypic.com/21103ld.png
What I want is that button to be set up at the bottom of the screen(!from my point of view
).
But I don't know how to achieve that.Thanks
EDIT1:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
>
<SurfaceView android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="@+id/surface_camera" />
<RelativeLayout android:layout_width="180dp"
android:layout_height="fill_parent"
>
<Button android:layout_width="fill_parent"
android:layout_height="320dip"
android:id="@+id/btnPhoto"
android:layout_alignParentBottom="true"
android:text="Take Photo"
android:layout_gravity="bottom|left" />
</RelativeLayout>
</RelativeLayout>
SOLUTION:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
>
<SurfaceView android:layout_width="450dip"
android:layout_height="fill_parent" android:id="@+id/surface_camera" />
<RelativeLayout android:layout_width="180dp"
android:layout_toRightOf="@id/surface_camera"
android:layout_height="fill_parent"
>
<Button android:layout_width="fill_parent"
android:layout_height="320dip"
android:id="@+id/btnPhoto"
android:layout_alignParentBottom="true"
android:text="Take Photo"
android:layout_gravity="bottom|right" />
</RelativeLayout>
</RelativeLayout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编辑
试试这个
尝试像这样改变你的布局,
EDIT
Try this
Try changing your layout like this,
尝试使用:
android:layout_alignParentButtom="true"
Try using:
android:layout_alignParentButtom="true"