在LinearLayout中对齐左侧的textview(水平)
问题描述:
我试图让我的Textview
对齐到左侧尝试过。和android:gravity="left"
但没有发生。在LinearLayout中对齐左侧的textview(水平)
这是我的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>
答
尝试这种使用RelativeLayout
insted的的LinearLayout
,使您的TextView
android: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>
答
的gravity
属性是用来设置的内容的严重性View
。
layout_gravity
属性用于设置视图本身与其父项的重力。
所以,如果你想设置TextView
中的文本的严重性,那么你会使用gravity
。如果你想在LinearLayout
内设置TextView
的重力,你应该使用layout_gravity
。
答
试试这个使用代码:
<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>
答
如果你想使用线性布局,然后使用:
<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"/>
尝试安卓layout_gravity = “左” –