Problem with layout_gravity.

by Aevea » Wed, 19 Jan 2011 09:48:35 GMT


Sponsored Links
 In my main.xml layout_gravity works normally with LinearLayout and
when you use setContentView(R.layout.main);
But if I inflate this xml file and then add it on screen using
addContentView or addView layout_gravity stops work - content of
main.xml draw in top position of screen.
Here is the code:

public class LayoutDoubleInflatingTest extends Activity {

        LinearLayout ll;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        RelativeLayout rl = (RelativeLayout)
findViewById(R.id.main_rl);

        LayoutInflater inflanter = getLayoutInflater();
        ll = (LinearLayout) inflanter.inflate(R.layout.test1, null,
false);

        LayoutParams param = new
LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT);

        rl.addView(ll, param);
    }
}



main.xml source:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android=" http://schemas.android.com/apk/res/ 
android"
    android:id="@+id/main_rl"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView
        android:id="@+id/text1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    android:gravity="right"
    />
</RelativeLayout>

test1.xml source:
<?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:layout_gravity="bottom"
  >
  <RelativeLayout
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
    >

  <TextView
        android:id="@+id/ttt1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="AAAAAAAAAA"
  />
  </RelativeLayout>
</LinearLayout>

-- 



Re: Problem with layout_gravity.

by Zsolt Vasvari » Wed, 19 Jan 2011 10:55:47 GMT


 RelativeLayout doesn't support the layout_gravity attribute, if you
want to align to the bottom, set the height to wrapped_content and
layout_alignParentBottom="true"




-- 


Sponsored Links


Other Threads

1. Possible to center items in submenu

Curious as to when my submenu pops up if I can center the items in
it.  Is this done in Android apps.  or any unneeded feature?  Also,
what kind of advanced formatting can you do to the menu?

-- 

2. browse picture gallery

Hi Friends,
I am developing an android application in which i have to browse
picture gallery or picture folder by clicking on a browse button and
then have to select a picture. I dont know how to do that. I have done
that in .Net but have no idea how to do in android. Is there anyone
who can help me? Thanks in advance :)

BR,
Zeeshan

-- 

3. How to create an executable file for android

4. Implementing seek bar for playing videos

5. WakefulIntentService - Question for Mark

6. Content Provider - any file type store..?

7. Samplesync adapter download problem