Reputation: 471
I am a beginner. I am developing an application where am facing a strange problem with layout. WHen I run my application in small devices it works fine, but when I run it on big screen device its layout properties changes automatically. Please let me know if there is any way that I can create a single layout programatically for all screen sizes? my xml is,
<RelativeLayout android:id="@+id/contents"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageButton
android:id="@+id/imgBtn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@drawable/panchangtab1" />
<ImageButton
android:id="@+id/imgBtn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_toRightOf="@+id/imgBtn1"
android:background="@drawable/horoscopetab1" />
</RelativeLayout>
here I am getting first image ok but second image is not in actual size.
Upvotes: 3
Views: 2618
Reputation: 375
You can use different qualifiers to create multiple layouts for different screens like this :
layout-hdpi/mylayout
you should read this .
Upvotes: 0
Reputation: 1389
It works for me
use weightsum in declaration of your layout will help you.
<LinearLayout
android:weightSum="100" //This is horizontal layout so will work for width
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<EditText
android:id="@+id/txt1"
android:layout_weight="40" //40% for text1
android:layout_height="40dp"
>
</EditText>
<EditText
android:id="@+id/txt2"
android:layout_weight="60" //60% for text2
android:layout_height="50dp"
>
</EditText>
</LinearLayout>
Upvotes: 1
Reputation: 7439
You can use match_parent, wrap_content, fill_parent etc. like attribute, dont create hard coded layouts file. Use 9 patch images, not static, not all the case satisfies your condition to use 9 patch, but when you found that some images can work in 9 patch so make it 9 patch, this is only for ImageView not for all component, remaining things TextViews, EditText etc. You can create with your own, BUT DONT CREATE HARD CODED LAYOUT.
Upvotes: 0
Reputation: 2969
You should use match_parent and wrap_content on your layout file. Use them in RelativeLayout or LinearLayout or bla bla.
If you want a ImageView, TextView, Button... was covered whole screen width, you should use fill_parent on layout_width. Also, if you want a ImageView, TextView, Button... was covered whole screen height, you should use fill_parent on layout_height.
You can check this LayoutParams
Upvotes: 0
Reputation: 2530
Please go through the following web site for developing multiple screen support application.
http://developer.android.com/training/multiscreen/index.html (Follow the sub links also) http://developer.android.com/guide/practices/screens_support.html
Upvotes: 0
Reputation: 93
You have to use fill_parent , match_parent , wrap_content units for width and height of the layouts.....and also you have to use weight for layouts instead hard coding the height and width.
check this link for multi screen supporting layouts...... http://developer.android.com/guide/practices/screens_support.html
Upvotes: 3