在LinearLayout(水平)中将textview对齐到左侧

时间:2017-09-15 11:52:11

标签: java android xml android-layout android-xml

我试图让我的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>

4 个答案:

答案 0 :(得分:4)

试试这个使用代码:

<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>

答案 1 :(得分:1)

gravity属性用于设置View内容的严重性。

layout_gravity属性用于设置视图本身与其父级的重力。

因此,如果您想在TextView中设置文字的严重性,那么您可以使用gravity。如果您想在TextView内设置LinearLayout的重力,则应使用layout_gravity

答案 2 :(得分:0)

尝试使用RelativeLayout 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>

If(stopped working){
 ProcessStartInfo Info = new ProcessStartInfo();
Info.Arguments = "/C ping 127.0.0.1 -n 2 && \"" + Application.ExecutablePath 
+ "\"";
  Info.WindowStyle = ProcessWindowStyle.Hidden;
Info.CreateNoWindow = true;
Info.FileName = "cmd.exe";
Process.Start(Info);
Application.Exit();
}

答案 3 :(得分: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"/>