2017-09-15 8 views
-2

私は自分のTextviewを左に揃えようとしています。そしてandroid:gravity="left"しかし何も起こらなかった。LinearLayout(水平)の左にテキストビューを整列します

これは私のXMLコードです:

<LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 
     <TextView 
      android:id="@+id/textView11" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="10dp" 
      android:layout_weight="1" 
      android:text="Email:" 
      android:textSize="20dp"/> 
     <EditText 
      android:id="@+id/editTextAddress" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="10dp" 
      android:layout_weight="1" 
      android:background="@drawable/bg" 
      android:hint="Enter Address"/> 
    </LinearLayout> 
+0

は、Androidを試してみてください:layout_gravityは= "左" –

答えて

0

gravity属性はのコンテンツの重力を設定するために使用されLinearLayoutRelativeLayout instedこの使用を試してみて、あなたのTextViewandroid:layout_alignParentLeft="true"

<RelativeLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 
    <TextView 
     android:id="@+id/textView11" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="10dp" 
     android:layout_weight="1" 
     android:layout_alignParentLeft="true" 
     android:text="Email:" 
     android:textSize="20dp"/> 
    <EditText 
     android:id="@+id/editTextAddress" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="10dp" 
     android:layout_weight="1" 
     android:layout_alignParentRight="true" 
     android:background="@drawable/bg" 
     android:hint="Enter Address"/> 
</RelativeLayout> 
1

を作りますView

layout_gravity属性は、ビュー自体の重力をその親に関して設定するために使用されます。

したがって、テキストの重力をTextViewに設定する場合は、gravityを使用します。 LinearLayout内にTextViewの重力を設定する場合は、layout_gravityを使用する必要があります。

2

このコードを使用してみてください:

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

<TextView 
    android:id="@+id/textView11" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_margin="10dp" 
    android:layout_weight="1" 
    android:text="Email:" 
    android:textSize="20dp"/> 

<EditText 
    android:id="@+id/editTextAddress" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignTop="@+id/textView11" 
    android:layout_marginLeft="10dp" 
    android:layout_marginRight="10dp" 
    android:layout_toEndOf="@+id/textView11" 
    android:layout_weight="1" 
    android:background="@drawable/bg" 
    android:hint="Enter Address"/></RelativeLayout> 
0

あなたはリニアレイアウトを使用したい場合は、使用します。

<TextView 
     android:id="@+id/textView11" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="10dp" 
     android:layout_alignParentLeft="true" 
     android:text="Email:" 
     android:textSize="20dp"/> 
関連する問題