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. [WTA] Zyrex Onepad SP1110, NVidia Tegra Dual-Core ARM Cortex A9

Spek menarik
Harga nya berapa bang ocu?




Dear suhu suhi RR id-android

saya penasaran dg Zyrex OnePad SP1110
spec nya menggiurkan (saya attach pic nya+spec)

bbrp nilai plus Zyrex Onepad SP1110 :

- NVidia Tegra Dual-Core ARM Cortex A9 1Ghz
- 10,1" multitouch capacitive 1024x600 (resolusinya lbh besar dari axioo
picopad)
- 1x USB (kayaknya bisa USB on the go nih)
- HDMI out
- camera

minus : fungsi telephony

kira2 sdh ada yg pernah icip2 ???

TIA

-- 
===============
"

-- 
===============
"

2. Diasplay gtab tdk bisa landcape

para suhu semua, display gtab saya mendadak hanya bisa portrait, alias
tidak bisa otomatis landscape jika posisi dimiringkan. Mohon
pencerahan, bagaimana cara settingnya biar bisa kembali normal. Maklum
newbie baru megang gtab.


Rgds,

Oetjoe

-- 
===============
"

3. [WTB] headset HTC EVO OEM

4. Cerita android

5. regarding onretainnonconfigurationinstance

6. Disable a TabHost/Layout

7. Ketika Blackberry Menggandeng Android