2014-09-06 76 views
1

我对Android布局设计感到困惑。我想达到以下图像中的布局:enter image description hereAndroid LinearLayout:Layout中的布局

但下面的代码产生这样的形象: enter image description here

我的代码

<LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="50sp" 
     android:layout_below="@+id/view" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:background="@drawable/bg_shadow" 
     android:animateLayoutChanges="true" 
     android:layout_marginTop="5dp" 
     android:id="@+id/detailsLay"> 

     <CheckBox 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/repeat" 
      android:id="@+id/repeatCheckBox" 
      android:longClickable="false" 
      android:textColor="@android:color/background_light" 
      android:paddingTop="15sp" 
      android:paddingRight="15sp" 
      android:paddingLeft="1sp" 
      android:paddingBottom="15sp" /> 
     <TextView 
      android:layout_width="30dp" 
      android:layout_height="20sp" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:text="@string/sat" 
      android:id="@+id/satTextView" 
      android:layout_gravity="center_vertical|right" 
      android:textColor="@android:color/holo_orange_light" 
      android:layout_marginLeft="2sp" /> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/arrowDown" 
      android:src="@android:drawable/arrow_down_float" 
      android:layout_gravity="center_vertical" /> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 

      <CheckBox 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/everyday"/> 
     </LinearLayout> 
    </LinearLayout> 
+0

使用'relativeLayout'代替 – suitianshi 2014-09-06 04:53:36

+0

使用'RelativeLayout'否则使用'LinearLayour2'的不同布局 – SilentKiller 2014-09-06 04:55:55

回答

3

这仅仅是一个示例XML从中学习。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <Button 
      android:id="@+id/button1" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Button" /> 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Large Text" 
      android:textAppearance="?android:attr/textAppearanceLarge" /> 

     <ImageView 
      android:id="@+id/imageView1" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:src="@drawable/ic_launcher" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <Button 
      android:id="@+id/button2" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Button" /> 

     <CheckBox 
      android:id="@+id/checkBox1" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="CheckBox" /> 

     <TextView 
      android:id="@+id/textView2" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Large Text" 
      android:textAppearance="?android:attr/textAppearanceLarge" /> 
    </LinearLayout> 

</LinearLayout> 

使用线性布局的权重和用户方向等属性。

+0

Bingo !!!非常感谢。 @Shabbir :) – rony36 2014-09-06 05:06:18

+0

欢迎开心编码。 – 2014-09-06 05:19:38