【发布时间】:2018-11-03 04:07:19
【问题描述】:
我有这样一个带有自定义顶部标题的布局。我希望ImageView 位于标题的中间,即center_horizontal。我尝试为布局设置布局重力和重力,但有时还可以。但是,当我在横向模式下尝试应用程序时,徽标转到一侧,并且图像不在布局的正确中心。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/phoneoptLayout"
android:background="@mipmap/bgg"
android:paddingBottom="5dp"
android:orientation="vertical"
android:paddingLeft="5dp"
android:paddingRight="6dp">
<LinearLayout
android:id="@+id/top"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/back"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="left"
android:layout_marginLeft="5dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:paddingTop="10dp"
android:src="@drawable/arrow_back" />
<ImageView android:src="@mipmap/logo"
android:layout_width="wrap_content"
android:layout_height="55dp"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:layout_marginRight="30dp"
android:layout_gravity="center_horizontal" />
</LinearLayout>
</LinearLayout>
在另一种布局中,标题右侧有一个退出按钮。这也不在中心。我是 android 新手,所以我不知道如何解决这个问题。
【问题讨论】:
-
我认为您的标签以RelativeLayout 开头并以Linearlayout 结尾。什么是实际使用必须使用?
-
你能把页面截图添加到横向吗?
标签: android positioning android-relativelayout