How to keep Relative layout right side in LinearLayout of android

Home - How to keep Relative layout right side in LinearLayout of android

Ikrar Ilyas asked 7 months ago

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>
1 Answers
Avianto Staff answered 7 months ago

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