How Does One Align Views At Certain Positions Of The Screen, Staying Consistent Across Multiple Screen Resolutions?
Solution 1:
I have found a solution! One that is completely relative to itself, and does not rely on pixels or density pixels at all.
I've placed a TextView of 0x0 in the middle of the screen, and put RelativeLayouts on top of and below it, filling the screen.
Then I placed two TextViews of 0x0 in the middle of those layouts, and within those layouts, two new RelativeLayouts. One below the highest TextView, one above the lowest. I placed my buttons in the center of those layouts.
It works like a charm, and does not rely on anything but the code itself.
This is my code now:
<?xml version="1.0" encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:background="@drawable/mainbg"><TextViewandroid:text=" "android:id="@+id/ankermidden"android:layout_centerVertical="true"android:layout_width="0dp"android:layout_height="0dp"></TextView><RelativeLayoutandroid:id="@+id/ankerveldboven"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_above="@id/ankermidden"><TextViewandroid:text=" "android:id="@+id/ankerboven"android:layout_centerVertical="true"android:layout_width="0dp"android:layout_height="0dp"></TextView><RelativeLayoutandroid:id="@+id/ankerveldmidboven"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_below="@id/ankerboven"><Buttonandroid:text="@string/topbutton"android:background="@drawable/silvertablesbuttonbgkort"android:id="@+id/topbutton"android:layout_alignParentRight="true"android:layout_centerInParent="true"android:layout_width="wrap_content"android:layout_height="wrap_content"android:gravity="center|center_vertical"></Button></RelativeLayout></RelativeLayout><RelativeLayoutandroid:id="@+id/ankerveldonder"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_below="@id/ankermidden"><TextViewandroid:text=" "android:id="@+id/ankeronder"android:layout_centerVertical="true"android:layout_width="0dp"android:layout_height="0dp"></TextView><RelativeLayoutandroid:id="@+id/ankerveldmidonder"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_above="@id/ankeronder"><Buttonandroid:text="@string/midbutton"android:background="@drawable/silvertablesbuttonbglang"android:id="@+id/midbutton"android:layout_alignParentRight="true"android:layout_centerInParent="true"android:layout_width="wrap_content"android:layout_height="wrap_content"android:gravity="center|center_vertical"></Button></RelativeLayout></RelativeLayout><RelativeLayoutandroid:id="@+id/underbar"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentBottom="true" ><Buttonandroid:text="@string/underbartekst"android:background="@drawable/silvertablesunderbar"android:id="@+id/underbarbutton"android:layout_width="match_parent"android:layout_height="wrap_content"android:paddingLeft="20dp"android:textSize="20dp"android:gravity="left|center_vertical" ></Button></RelativeLayout>
So yeah, that was easier than I thought.
Bill Gary suggested using a margin in dp which would keep the same proportions on different screen sizes, but after a lot of experimenting, things end up looking weird for me on different screens again.
I'll do some more experimenting before I'll get back to that, because this whole dip-margins thing is weirding me out... Things that should be displayed properly are not, and things that just shouldn't, do, on some screen resolutions.
I'll start doing my homework on that stuff, but for now, albeit it being a bit long, the code I posted above works flawlessly for me.
Solution 2:
try this, you may have to adjust the dp android:layout_marginTop="150dp"
<Buttonandroid:text="@string/topbutton"android:background="@drawable/silvertablesbuttonbgkort"android:id="@+id/topbutton"android:layout_alignParentRight="true"android:layout_marginTop="150dp"android:layout_width="wrap_content"android:layout_height="wrap_content"android:gravity="center|center_vertical"></Button>
Post a Comment for "How Does One Align Views At Certain Positions Of The Screen, Staying Consistent Across Multiple Screen Resolutions?"