Rockin
Rockin

Reputation: 743

Design problem with android

enter image description here

Little confused with the design in android..suppose i need to position two blocks

as in the figure..what shall i do?..if we use pixels the design looks different in different phones.

Design should be fixed in all phones..but how without using px we can design as above

Upvotes: 0

Views: 305

Answers (3)

Shailendra Singh Rajawat
Shailendra Singh Rajawat

Reputation: 8242

If dip is unable 2 solve ur problm , surely any of these approaches will work :

1) take a 9patch backgroud with proportionate padding . now put first textview with gravity left|top and second with grvity right|bottom . done

or

2)Take two child of a vertical linearlayot with layout_weight=1 , so will each will take 50% height now to put put textview center vertical . now lets try fix it horizontally.4 each text take two child textview with layout_weight=1 ,put text center_horizontal .for upper text male second invisible n for lower make first one invisible ......

Upvotes: 0

jsw
jsw

Reputation: 728

You could generate the layout in Java by getting the screen size and placing two objects (defined in xml or java) into the parent layout, taking into account the ratios.

Upvotes: 0

Dinesh Sharma
Dinesh Sharma

Reputation: 11571

Use two LinearLayout in your layout xml and set layout_marginLeft,layout_marginTop,layout_marginRight in dip according to the need.

See the following layout, its very similar to the one you want:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content">

    <Button 
        android:text="Button01" 
        android:id="@+id/Button01" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_marginTop="50dip"
        android:layout_marginLeft="30dip"
        ></Button>

        <Button 
        android:text="Button02" 
        android:id="@+id/Button02" 
        android:layout_below="@id/Button01"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_marginTop="140dip"
        android:layout_marginRight="30dip"
        ></Button>
</RelativeLayout>

Hope this will solve your issue.

Upvotes: 1

Related Questions