Shiv
Shiv

Reputation: 191

How to keep Relative layout right side in LinearLayout of android

I have LinearLayout inside that relataive layout is there. I want to keep RelativeLayout right side of the LinearLayout. How to do this one. below is my code

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

Upvotes: 1

Views: 374

Answers (2)

Dileep Patel
Dileep Patel

Reputation: 1988

@ Shiv you can try this ..hope this can help you,,

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

Upvotes: 1

sushildlh
sushildlh

Reputation: 9056

use this one

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

Note:-Weight is divide you parent LinearLayout into 2 View with same space .IF you want space between 2 views that put weight in ratio....

Upvotes: 2

Related Questions