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. Getting driving directions from application

Hello,

In my application I want to show route between two points and display
points (something like POI's from my own source) the user will be
riding through.

How can I get the directions (polyline) from GoogleMaps? Application
will not provide any navigation so I suppose that there are no "leagal
obstacles" for doing this (correct me please if I'm wrong)


Skyman
--~--~---------~--~----~------------~-------~--~----~

2. How to Start application On-Install

Hi,
I want to start my application just after it gets installed on the
device. Is there any way out in Android to do so.
I was wondering if there is any receiver to get informed on package
installed.
Regards
--~--~---------~--~----~------------~-------~--~----~

3. Is Android complaint with VCARD 2.1 specification ?

4. How to drop the AppWidget to Home Screen?

5. Access protected member variables in Android classes

6. how to capture event FINISH LOADING ListView and GridView

7. Access protected member variables in Android classes