Android Center布局隐藏按钮
我正在为我的第一个 Android 应用程序开发一个相当基本的屏幕布局,但遇到了一些问题。我的目标是在左上角和右上角有一个 TextView,在屏幕正中间有一个大的“hello world”TextView,然后在屏幕底部有一个按钮。我的问题是,要垂直居中“hello world”TextView,我需要设置layout_height =“fill_parent”。但是,这会导致中间的 TextView 覆盖并隐藏屏幕底部的按钮。有没有比我目前正在尝试的更好的方法来做到这一点?我在下面附上了我的 ui xml。谢谢!
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="1">
<TableRow>
<TextView
android:text="@string/label_left" />
<TextView
android:text="@string/label_right"
android:gravity="right" />
</TableRow>
</TableLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/hello_world"
android:gravity="center"
android:textSize="40sp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/next_activity"
android:gravity="center"
android:textSize="30sp" />
</LinearLayout>
I am working on a fairly basic screen layout for my first Android application and running into some issues. My goal is to have a TextView in the top left and top right corner, a large "hello world" TextView in the exact middle of the screen, and then a button at the bottom of the screen. My issue is, to center the "hello world" TextView vertically, I need to set the layout_height="fill_parent". However, this causes the middle TextView to cover and hide the button at the bottom of the screen. Is there a better way to do this than what I am currently trying? I have attached my ui xml below. Thanks!
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="1">
<TableRow>
<TextView
android:text="@string/label_left" />
<TextView
android:text="@string/label_right"
android:gravity="right" />
</TableRow>
</TableLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/hello_world"
android:gravity="center"
android:textSize="40sp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/next_activity"
android:gravity="center"
android:textSize="30sp" />
</LinearLayout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用RelativeLayout,则可以轻松地将其他视图与屏幕的顶部/底部对齐:
使用
android:layout_alignParentTop="true"
或
android:layout_alignParentBottom="true"
代码>左/右相同:
这个怎么样?
这是您正在寻找的吗?
If you use a RelativeLayout instead, you can align other views to the top/bottom of the screen easily:
use
android:layout_alignParentTop="true"
or
android:layout_alignParentBottom="true"
same for left/right :
What about this ?
Is it what you are looking for ?