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. How to capture unlock event in activity.

Hi,
    While mediaplayer playing rtsp stream if user press lock button and then
he press menu(unlock) mediaplayer shows blank screen. I want to know how to
capture this unlock event inside activity so that i can resume mediaplayer.

-- 

2. Samsung Captivate phone running Android 2.2 getting "Phone not connected"

I was all set to play with the App Inventor product using my Samsung
Captivate phone and things were looking pretty good until I tried to
get the phone working with the App Inventor product.

I have Android 2.2 installed on the phone and everything seams to work
fine, in that I can use the USB cable to move files back and forth
under normal operation.   Loading both music, video and photos upload
and download.    I opened the control panel and verified the Samsung
Android USB Composite device, it is saying I have the latest updated
drivers from Samsung dated 7/7/2010 and the driver version is
5.2.0.5 .

I do have The USB Debugging and Stay Awake checked.

My PC is running Windows Vista on a 64bit hp system.
I'm running Chrome on the pc version 7.0.517.44

I rebooted the pc and the phone after loading the App Inventor.

I am not seeing the application on the phone during the development,
If I try and do a download to the phone I get the error message  "The
Phone is Not Connected"

It sounds like a problem recognizing the drivers but they work for
moving files back and forth...

What do you think?



-- 

3. Is there way to create a slow motion method for video

4. Announcement: DynaDroid - an open source micro-framework for Android

5. Speech Recognition Help

6. Widget Not Updating Display

7. Live WallPaper and TextView