2014-10-03 68 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

回答