Skip to content


Android 50% width horizontal layout

Recently I needed to have percentage based layout (I wanted two ListViews side-by-side at 50% of the screen each). Below is an way to achieve it using LinearLayout with layout_weight:

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >
        
        <ListView
            android:id="@+id/lstPrev"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight=".50" />
        
        <ListView
            android:id="@+id/lstCur"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight=".50" />
       
</LinearLayout>

Notice that both ListViews have layout_width set to 0 and layout_weight set to .50 (for 50%)

Posted in Android. Tagged with , , , .