I am using only one root layout in my layout file and i cant add any nested layouts. How can I align all my views in center in all screens? For 480x800
the layout is perfect but if i change the emulator, everything is messed up.
If you want elements within a viewgroup centered, you should use the gravity
property on that viewgroup.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root"
android:orientation="vertical"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:gravity="center"
>
<TextView
android:id="@+id/tb1"
android:text="tb1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>
<TextView
android:id="@+id/tb2"
android:text="tb2"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>
<TextView
android:id="@+id/tb3"
android:text="tb3"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>
</LinearLayout>
The android:gravity
property defines how to align child elements, or the contents of the view.
android:layout_gravity
on the other hand defines rules which are passed to the parent, instructing the parent how to align this element.
A deeper explanation: http://thinkandroid.wordpress.com/2010/01/14/how-to-position-views-properly-in-layouts/
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加