我很难尝试将我的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>
答案 0 :(得分:0)
将此父级布局替换为:
<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 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"
android:gravity="center"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
答案 1 :(得分:0)
viewFirst.animate()
.x(viewSecond.x)
.y(viewSecond.y)
.setDuration(1000)
.withEndAction {
//to make sure that it arrives,
//but not needed actually these two lines
viewFirst.x = viewSecond.x
viewFirst.y = viewSecond.y
}
.start()