2015-10-29 58 views
-1

在此佈局中,我想將「語言」的位置更改爲右... 我使用佈局重力和重力沒有任何成功,任何人都知道如何以最少的更改進行操作?將LinearLayout更改爲從左到右

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

設置TextView的寬度,以填補行,然後設置重力 –

+0

使用相對佈局而不是和的LinearLayout保持該TextView的單獨的LinearLayout,你可以改變的然後它的位置。 – AndroidHacker

+0

混淆:'將LinearLayout更改爲從左到右'以及'將「的位置更改爲」右側「是兩個不同的事情。 。 LinearLayout也是水平的,這可能意味着額外的東西 。這是一個奇蹟,爲什麼現在有三種不同的意見。 – CmosBattery

回答

0

Onemore選項來嘗試

<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

添加機器人:supportsRtl =「true」以您的應用程序元素

那麼你可以試試這個 - >擁有整個佈局逆轉,不僅文本(這是扭轉它安卓的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> 
+0

我告訴layout_gravity不在這個佈局工作 –

+0

在框架佈局?我只是給了另一種選擇,如果你沒有任何具體的要求使用LinearLayout – kirotab

0

如果您想使用layout_gravity,請使用相對佈局。 否則,只需在電子郵件下面放置所需的文本。

+0

但是,然後他需要弄清楚元素之間的距離,否則他們會彼此靠近我認爲 – kirotab

+0

然後,他可以使用layout_weight(在他正在使用線性佈局)。 – Sid

+0

的確,我還想過它,但它不是再次包裝內容(但你是對的) – kirotab

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" /> 
相關問題