2017-12-10 2 views
0

TextView를 뷰의 왼쪽과 오른쪽에 배치하는 올바른 방법입니까?Stack TextView를 왼쪽 및 오른쪽으로 배열합니다.

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:layout_marginLeft="20dp" 
    android:layout_marginTop="3dp" 
    android:layout_below="@+id/l_section_login" 
    > 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/tv_forgot_password" 
     android:layout_gravity="left" 
     android:textStyle="normal" 
     android:text="Forgot Password?" /> 
    <TextView 
     android:id="@+id/tv_sign_up" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="180dp" 
     android:text="Sign up?" 
     /> 
</LinearLayout> 

답변

1

아니요, 180dp을 여백으로 하드 코딩했습니다. 이렇게하면 화면 크기가 다른 기기를 정상적으로 처리하지 못합니다.

나는 ConstraintLayout로 시작하고 당신은 여전히 ​​당신은 예를 들어, 비어있는보기 및 사용의 무게와 라인을 채울 수있는 선형 레이아웃을 사용하려면 두 번째 텍스트 뷰

<android.support.constraint.ConstraintLayout 
    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" 
    > 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Left" 
     /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Right" 
     app:layout_constraintEnd_toEndOf="parent" 
     /> 

</android.support.constraint.ConstraintLayout> 
0

app:layout_constraintEnd_toEndOf="parent"를 사용하는 것이 좋습니다 것입니다 :

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:weightSum="1" 
     android:orientation="horizontal"> 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_weight="0.3" 
      android:text="Forgot Password?" 
      android:gravity="center_vertical" /> 

     <TextView 
      android:id="@+id/textView2" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_weight="0.5" 
      android:gravity="center_vertical" /> 

     <TextView 
      android:id="@+id/textView3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="right" 
      android:layout_weight="0.2" 
      android:text="Sign up?" /> 
    </LinearLayout> 
</LinearLayout> 
관련 문제