Java Android应用程序-如何将对象定位到屏幕的顶部和底部?
我正在尝试创建一个简单的android应用程序,在屏幕的顶部和底部显示一个黑条,因为我不喜欢现在所有手机都有的圆形屏幕角的新趋势,而且目前似乎没有任何不需要根手机的解决方案。我试图隐藏圆角,以创建更传统、更美观的矩形显示外观,使用系统覆盖来覆盖所有其他应用程序。这是我当前用于覆盖的代码,基于此 结果是状态栏下方和导航栏上方出现一个黑色条,如图所示 我是Android开发新手,所以不知道如何将这些条定位到屏幕的绝对顶部和底部 另一个问题是,当打开以横向模式运行的应用程序时,我的叠加应用程序的黑色条也会旋转,因此它们位于屏幕的两侧 我已经将android:screenOrientation=“肖像”添加到清单文件中,但这没有什么区别Java Android应用程序-如何将对象定位到屏幕的顶部和底部?,java,android,android-studio,android-11,Java,Android,Android Studio,Android 11,我正在尝试创建一个简单的android应用程序,在屏幕的顶部和底部显示一个黑条,因为我不喜欢现在所有手机都有的圆形屏幕角的新趋势,而且目前似乎没有任何不需要根手机的解决方案。我试图隐藏圆角,以创建更传统、更美观的矩形显示外观,使用系统覆盖来覆盖所有其他应用程序。这是我当前用于覆盖的代码,基于此 结果是状态栏下方和导航栏上方出现一个黑色条,如图所示 我是Android开发新手,所以不知道如何将这些条定位到屏幕的绝对顶部和底部 另一个问题是,当打开以横向模式运行的应用程序时,我的叠加应用程序的黑色
我怎样才能使黑条保持在屏幕的上边缘和下边缘,而不考虑应用程序的旋转?我认为您可以尝试像这样重新设计activity.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:background="@android:color/background_dark"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="500dp"
android:background="@android:color/holo_blue_dark">
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="HELLO WORLD"
android:textAlignment="center"
android:textColor="#000000"
android:textSize="28sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
我认为您可以尝试像这样重新设计activity.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:background="@android:color/background_dark"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="500dp"
android:background="@android:color/holo_blue_dark">
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="HELLO WORLD"
android:textAlignment="center"
android:textColor="#000000"
android:textSize="28sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
感谢您的回复这似乎没有什么不同,覆盖仍然会旋转,并显示在状态栏下和导航栏上方。换句话说,您希望全屏显示自定义布局和方向?是的,但我仍然希望能够在横向应用程序中使用其他应用程序,同时覆盖层保持纵向。你必须像这样声明“纵向”<代码>感谢您的回复这似乎没有任何区别,覆盖仍然会旋转,并且仍然显示在状态栏下方和导航栏上方。换句话说,您希望全屏显示自定义布局并将其作为方向?是的,但我仍然希望能够在横向应用程序中使用其他应用程序,同时覆盖层保持纵向。你必须像这样声明“纵向”<代码>