ConstrainLayout을 사용하려고하지만 사용하기가 어렵습니다. 나는 스크린과 같은 설정을위한 레이아웃을 가지고 있으며 매우 간단하고 구현하기 쉬운 LinearLayout과 RelativeLayout을 사용하고 있습니다. 여기 레이아웃입니다 :LinearLayout 및 RelativeLayout을 ConstraintLayout으로 변환하는 방법은 무엇입니까?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv_stay_awake"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Stay awake"
android:padding="10dp"/>
<Switch
android:id="@+id/switch_stay_awake"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv_notification"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enable Notification"
android:padding="10dp"/>
<Switch
android:id="@+id/switch_notification"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enable location"
android:padding="10dp"/>
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"/>
</RelativeLayout>
</LinearLayout>
가 지금은 동일한 설정의 UI를 구축하기를 원하지만 ConstrainLayout를 사용하고 여기에 ConstrainLayout 인이 UI를 설정을 내가 가진 .
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<TextView
android:id="@+id/tv_stay_awake"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="Stay awake"/>
<Switch
android:id="@+id/switch_stay_awake"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintRight_toRightOf="parent" />
<TextView
android:id="@+id/tv_notification"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="Enable Notification"
app:layout_constraintTop_toBottomOf="@+id/tv_stay_awake"/>
<Switch
android:id="@+id/switch_notification"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/switch_stay_awake"/>
<TextView
android:id="@+id/tv_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="Enable location"
app:layout_constraintTop_toBottomOf="@+id/tv_notification"/>
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/switch_notification"/>
</android.support.constraint.ConstraintLayout>
, 스위치 버튼은 텍스트 뷰에 정렬되지 않습니다. 같은 라인 레벨의 TextView와 어떻게 정렬시킬 수 있습니까? LinearyLayout과 RelativeLayout을 사용했을 때와 똑같이 보일 것입니다. TextView 및 Switch 단추를 각 줄마다 RelativeLayout에 넣을 수는 있지만, 그렇게하면 ConstrainLayout을 사용할 이유가 없습니다.
이 지금은 각 설정 사이의 구분선을 추가 할 OUTPUT, 새로운 전망을 도입하지 않고 그것을 할 수있는 방법은 무엇입니까? –
나는 길을 가지지 않았다. 내가 이것을하고 싶다면, 새로운 'View'를 줄 구분자로 추가 할 것이다. – KeLiuyue