2014-10-03 73 views
0

所以我是新來的android和需要一些建議和幫助我想要實現的佈局。如何正確佈局Android活動?

所以我想要把兩個或更多的控件在一行中彼此相鄰...我使用LinearLayout來實現這一點。但我不得不做的是左側的控制我已經給了一個寬度來推動另一個控制到右側......所以我拿起了不同的屏幕分辨率這個問題。如果分辨率不如我的測試設備(Samsung S3)那麼高,那麼由於左側控件的寬度,右側的控件會因爲無法移動而被壓扁。

我需要的是像Bootstrap拉左和拉右,然後我可以從左側或右側設置填充,這將解決我的問題...我如何在Android中實現這一點?

高分辨率 High Resolution

較低的分辨率 Lower Resolution

<ScrollView 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="vertical" 
tools:context=".MainActivity$TestFragment" > 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="7dp" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:layout_marginTop="7dp" 
     android:gravity="center_vertical" 
     android:orientation="horizontal" > 

     <TextView 
      android:layout_width="250dp" 
      android:layout_height="wrap_content" 
      android:gravity="center_vertical" 
      android:paddingLeft="10dp" 
      android:text="Test Label" 
      android:textColor="@color/black" 
      android:textColorHint="@color/black" 
      android:textSize="12sp" /> 

     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center_vertical" 
      android:inputType="numberDecimal" 
      android:paddingLeft="10dp" 
      android:textColor="@color/black" 
      android:textColorHint="@color/light_grey" 
      android:textSize="15sp" /> 
    </LinearLayout> 


</RelativeLayout> 

+0

嘗試使用機器人:在這兩個的TextView和EditText上 – 2014-10-03 08:31:04

+0

檢查layout_weight =「0.5」,並告訴我結果 – 2014-10-03 08:33:45

+0

這似乎是工作,但由於我的一些標籤比其他標籤長,EditText Views都是我不喜歡的不同大小。有沒有辦法控制EditText的寬度,因爲在使用layout_weight時看起來不行 – Sethles 2014-10-03 09:09:23

回答