2016-09-26 61 views
1

我在里面有LinearLayout,里面有那个relataive布局。我想保留LinearLayout的RelativeLayout右侧。如何做到这一点。下面是我的代码如何在LinearLayout中保留相对布局右侧android

<LinearLayout android:id="@+id/status_bar_contents" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingStart="6dp" 
    android:paddingEnd="8dp" 
    android:orientation="horizontal"> 

    <com.android.keyguard.AlphaOptimizedLinearLayout android:id="@+id/system_icon_area" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:orientation="horizontal"> 

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

      <ImageView 
       android:id="@+id/network" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerVertical="true" 
       android:gravity="center"     
       android:layout_marginRight="20dp"    
       android:background="@drawable/network_strength_0"/>  
      <com.android.systemui.statusbar.policy.Clock 
       android:id="@+id/clock" 
       android:textAppearance="@style/TextAppearance.StatusBar.Clock" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerInParent="true" 
       android:singleLine="true" 
       android:gravity="center" 
       android:layout_toRightOf="@id/network" 
       /> 
      </RelativeLayout>  
     </com.android.keyguard.AlphaOptimizedLinearLayout> 
    </LinearLayout> 
+0

我不知道这是否可能我知道这是如果你把所有东西放在网格视图中,你应该能够轻松地将它们放在海誓山盟旁边。让我知道它是否工作 –

回答

1

@希夫你可以试试这个..hope这可以帮助你,,

<LinearLayout android:id="@+id/status_bar_contents"    
android:layout_width="match_parent"    
android:layout_height="match_parent"  
android:paddingStart="6dp"  
android:paddingEnd="8dp" 
android:weightSum="1"  
android:orientation="horizontal">  

<com.android.keyguard.AlphaOptimizedLinearLayout  android:id="@+id/system_icon_area" 
    android:layout_width="0dp" 
    android:layout_weight=".5" 
    android:layout_height="match_parent"> 


    </com.android.keyguard.AlphaOptimizedLinearLayout> 

    <RelativeLayout 
     android:layout_width="0dp" 
     android:layout_weight=".5" 
     android:layout_height="wrap_content">    

     <ImageView 
      android:id="@+id/network" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:gravity="center"     
      android:layout_marginRight="20dp"    
      android:background="@drawable/network_strength_0"/>  

     <com.android.systemui.statusbar.policy.Clock 
      android:id="@+id/clock" 
      android:textAppearance="@style/TextAppearance.StatusBar.Clock" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:singleLine="true" 
      android:gravity="center" 
      android:layout_toRightOf="@id/network"/>  
     </RelativeLayout>  
</LinearLayout> 
+0

感谢您的重播。还有一件事是在clocl后添加了一个更多的图像视图,即android:layout_toRightOf =“@ id/clock”。只是我想给clocl和新形象之间多一些空间。如何给? – Shiv

+1

嗨,你可以在第二个ImageView中设置[android:layout_marginLeft =“10dp”]。 –

2

使用这一个

<LinearLayout android:id="@+id/status_bar_contents" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingStart="6dp" 
    android:paddingEnd="8dp" 
    android:orientation="horizontal"> 

    <com.android.keyguard.AlphaOptimizedLinearLayout android:id="@+id/system_icon_area" 
     android:layout_width="0dp" 
     android:layout_weight="1" 
     android:layout_height="match_parent" 
     android:orientation="horizontal"> 


     </com.android.keyguard.AlphaOptimizedLinearLayout> 

     <RelativeLayout 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="wrap_content">    

      <ImageView 
       android:id="@+id/network" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerVertical="true" 
       android:gravity="center"     
       android:layout_marginRight="20dp"    
       android:background="@drawable/network_strength_0"/>  
      <com.android.systemui.statusbar.policy.Clock 
       android:id="@+id/clock" 
       android:textAppearance="@style/TextAppearance.StatusBar.Clock" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerInParent="true" 
       android:singleLine="true" 
       android:gravity="center" 
       android:layout_toRightOf="@id/network" 
       /> 
      </RelativeLayout>  
    </LinearLayout> 

注: - 重量是。如果你想要的是把重量比2次之间的空间划分,你父母的LinearLayout到2查看与同一空间....

+0

位相对布局不适合父布局的右侧 – Shiv