Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

layout "include" feature doesn't support layout_gravity property?

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <include
        layout="@layout/view1" 
        android:layout_gravity="center_vertical" />

    <include
        layout="@layout/view2"
        android:layout_gravity="center_vertical" />
</LinearLayout>

So, android:layout_gravity will be always ignored? That's really bad for code reusability... It seems like layout_margin doesn't supported either.

And here is view1.xml layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:minHeight="45dip"
    android:background="@drawable/updater_background" >

    <ProgressBar
        style="?android:attr/progressBarStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_marginRight="7dip"
        android:visibility="gone" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical" />
</LinearLayout>
like image 826
Dmitry Ryadnenko Avatar asked Dec 16 '10 07:12

Dmitry Ryadnenko


1 Answers

I think this can be solved by inserting weighted layout

For example

<LinearLayout
  android:orientation="vertical"
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context="com.sample.SampleActivity">

 <LinearLayout
    android:layout_weight="1"
    android:layout_width="match_parent"
    android:layout_height="0dp">

    <--Some other Views-->

</LinearLayout>


<include
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    layout="@layout/my_awesome_layout"
    />

The LinearLayout can be replaced with Space, if you don't want any component.

like image 174
Jeongmyeong Lee Avatar answered Sep 29 '22 12:09

Jeongmyeong Lee