【发布时间】:2018-05-06 15:37:56
【问题描述】:
我很难将我的 2 个线性布局居中。第一个线性布局使国家代码选择器和编辑文本在同一行。第二个线性布局假设将按钮放在第一个线性布局之下。但如果我将按钮放在第一个线性布局下,它就不会再居中了。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/ghostWhiteColor"
android:orientation="vertical"
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:padding="10dp"
android:gravity="center"
android:id="@+id/linearLayout1">
<com.hbb20.CountryCodePicker
android:id="@+id/ccp"
android:layout_width="86dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
app:ccp_showFullName="false"
app:ccp_showNameCode="false"
app:ccp_showPhoneCode="true" />
<com.rengwuxian.materialedittext.MaterialEditText
android:id="@+id/register_password"
android:layout_width="260dp"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
android:layout_marginTop="-2dp"
android:hint="@string/hint_phone"
android:inputType="phone"
android:padding="10dp"
android:singleLine="true"
app:met_floatingLabel="normal"
app:met_helperText="Enter your phone number."
app:met_helperTextAlwaysShown="true" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout2"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:padding="10dp"
android:gravity="center">
<com.rey.material.widget.Button
android:id="@+id/button_register_accept"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:background="@color/holo_blue_light"
android:padding="10dp"
android:paddingEnd="50dp"
android:text="@string/btn_accept"
android:textColor="@color/ghostWhiteColor" />
</LinearLayout>
</RelativeLayout>
【问题讨论】:
-
你能把你想要的截图放上来吗?
-
@diegoveloper 更新了当前线程的未居中示例。
-
好的,在下面查看我的解决方案
标签: android xml android-layout layout