将LinearLayout从左向右更改

时间:2015-10-29 20:07:33

标签: android android-layout

在这个布局中,我想将“ایمیل”的位置改为右边...... 我使用布局重力和重力没有任何成功,任何人都知道如何做最少的变化?

  <LinearLayout
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_marginTop="@dimen/margin_padding_small"
  android:orientation="horizontal" >

            <com.pt.chfnt.view.widget.OpenSansRegularTextView
            android:layout_width="@dimen/lblSignupHeaderWidth"
            android:layout_height="wrap_content"
            android:textColor="@color/primary_text"
            android:textSize="@dimen/text_size_normal"
            android:layout_marginLeft="@dimen/margin_padding_xxtiny"
            android:gravity="center_vertical"
            android:text="ایمیل:" />


            <com.pt.chfnt.view.widget.OpenSansRegularTextView
            android:id="@+id/lblEmail"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColor="@color/black"
            android:textSize="@dimen/text_size_xnormal"
            android:paddingTop="@dimen/margin_padding_small"
            android:paddingBottom="@dimen/margin_padding_small"
            android:layout_marginLeft="@dimen/margin_padding_xxnormal"
            android:layout_marginRight="@dimen/margin_padding_small"
            android:gravity="center_vertical"
            android:background="@drawable/layout_register"
            android:inputType="textEmailAddress" />

            </LinearLayout>

3 个答案:

答案 0 :(得分:0)

再试一次选择

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"     
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:layout_gravity="right"
        android:text="First"
        android:textDirection="rtl"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <TextView
        android:text="Second"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</FrameLayout>

修改

另一个选项不确定是否足够

我假设您已在清单文件中启用了rtl支持,如下所述: http://android-developers.blogspot.co.uk/2013/03/native-rtl-support-in-android-42.html

将android:supportsRtl =“true”添加到您的应用程序元素

然后你可以尝试这个 - &gt;整个布局不仅反转了文本(这是颠倒它的android:layoutDirection =“rtl”)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"     
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:orientation="horizontal"
    android:layoutDirection="rtl">
    <TextView
        android:text="First"
        android:textDirection="rtl"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <TextView
        android:text="Second"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</FrameLayout>

答案 1 :(得分:0)

如果要使用layout_gravity,请使用相对布局。 否则只需将所需文本放在电子邮件下面。

答案 2 :(得分:0)

这是我找到的最佳解决方案......

 android:id="@+id/lblEmail"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/black"
            android:textSize="@dimen/text_size_xnormal"
            android:paddingTop="@dimen/margin_padding_small"
            android:paddingBottom="@dimen/margin_padding_small"
            android:layout_marginLeft="@dimen/margin_padding_xxnormal"
            android:layout_marginRight="@dimen/margin_padding_small"
            android:gravity="center_vertical"
            android:background="@drawable/layout_register"
            android:inputType="textEmailAddress"
            android:layout_weight="0.90" />

            android:layout_width="@dimen/lblSignupHeaderWidth"
            android:layout_height="wrap_content"
            android:textColor="@color/primary_text"
            android:textSize="@dimen/text_size_normal"
            android:layout_marginRight="@dimen/margin_padding_xxtiny"
            android:gravity="center_vertical"
            android:text="ایمیل:"
            android:layout_weight="0.10" />