Java 将文本视图在线性布局中向左对齐(水平)
我正在尝试将我的Java 将文本视图在线性布局中向左对齐(水平),java,android,xml,android-layout,android-xml,Java,Android,Xml,Android Layout,Android Xml,我正在尝试将我的文本视图与左侧对齐。我已经尝试过了。还有android:gravity=“left”,但什么也没发生 这是我的XML代码: <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView
文本视图
与左侧对齐。我已经尝试过了。还有android:gravity=“left”,但什么也没发生
这是我的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
代替线性布局
,并使您的文本视图
使用
重力属性设置视图内容的重力
layout\u gravity
属性用于设置视图自身相对于其父视图的重力
因此,如果您想在TextView
中设置文本的重力,那么可以使用gravity
。如果要在LinearLayout
内设置TextView
的重力,应使用layout\u 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"/>
试试android:layout\u gravity=“left”
<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"/>