Android Multiple Screen Support Problem - android

I Have used my all my images in drawable-hdpi folder . why cannot my layout properly outcome my emulator with different sizes. I hava faced this error according to pictures.
I have also include following code in manifest file.
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:anyDensity="false"
/>
Here android:anyDensity="false" check both false and true but could not any change, and also use Resizable: true and android:smallScreens="false" also used but could not get any change.
my all images are 96dpi resolution and main background image size 480*800 for normal screen of hdpi(WVGA800). so what is the my problem please find out and help me. Thanks in advance.
Edited:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_height="fill_parent"
android:layout_width="fill_parent" android:background="#drawable/normalbg"
android:gravity="top">
<ImageView android:id="#+id/group1" android:background="#drawable/groupone"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentRight="true" android:layout_marginRight="5dip" android:layout_marginTop="138dip"/>
<ImageView android:id="#+id/group2" android:background="#drawable/grouptwo"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentRight="true" android:layout_below="#id/group1"
android:layout_marginRight="5dip"/>
<ImageView android:id="#+id/group3" android:background="#drawable/groupthree"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentRight="true" android:layout_below="#id/group2"
android:layout_marginRight="5dip"/>
<ImageView android:id="#+id/group4" android:background="#drawable/groupfour"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentRight="true" android:layout_below="#id/group3" android:layout_marginRight="7dip"/>
<LinearLayout android:orientation="horizontal"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentBottom="true" android:baselineAligned="true">
<ImageView android:id="#+id/backToLevel" android:background="#drawable/back"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentRight="true" android:layout_below="#id/group4"
android:layout_gravity="center_horizontal" android:layout_marginLeft="116dip" android:layout_marginBottom="3dip"/>
</LinearLayout>
</RelativeLayout>

I used drawable folder all images then get the all images. I used this all layout in Relative layout rather than linear, and Make the all it properties. I skip the margin , below and above properties. First on alignparentcenter is true, then below or above the that centered image. Its work fine then the above my layout.

I assume you youse RelativeLayout to show the back button on the buttom. Like this, it may hover over the menu buttons if there isnĀ“t enough space for it.
Consider adding the back button into the menu buttons' LinearLayout.
To resize the image, consider using a 9-Patch Drawable.

Related

How to setup the ImageButton to match screen for different device?

I add the picture for 48*48 , 72*72 and 96*96 to mdpi , ldpi and hdpi respective.
And add the following code in AndroidManifest.xml
<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>
First Question:
The app will capture the suitable picture by itself when I do the above operation ?
Second Question:
But how to setup the Button in the xml file ?
If app will capture the suitable picture by itself , so I have set the width and the height to match_parent like the following code?
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#android:drawable/btn1" />
Thanks in advance.
-------------------------------EDIT----------------------------
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:background="#000000"
>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageButton
android:id="#+id/FileButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_alignParentLeft="true"
android:src="#drawable/file_viewer"/>
<ImageButton
android:id="#+id/recordButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_centerInParent="true"
android:src="#drawable/record" />
<ImageButton
android:id="#+id/photo_record_mode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_alignParentRight="true"
android:src="#drawable/recordmode"/>
</RelativeLayout>
</LinearLayout>
I modify the code like the above.
And I install the APP to different size of device , for 4.7 inch and 7 inch.
But it seem use the same size of picture.
and I change from android:background to android:src.
It like the following picture
Does there has any wrong ??
Yes, Android will select the right image resource at runtime depending on the screen density. However, you should set layout_width and layout_height to wrap_content instead of match_parent.
The app will automatically get resources from the appropriate folder based on the device specs. Secondly, even though your image view is set to match parent, the image wont fill the parent because you have set the src property and not the background. If you want the image of imageView to fill the parent, change The image button declaration to this:
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:drawable/btn1" />
and if you want it to take the original size, do it like this:
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#android:drawable/btn1" />

Android ListView items: image and text too small

I'm working on a ListView where each item has an image and some text. On my older phone, HTC Evo 4G, things came up exactly as expected. Image is nicely sized and text looks fine. Then I loaded the same app on my new phone, HTC One, and the images are so tiny they are useless. I know the HTC One has a significantly higher resolution, but I cannot figure out how to make each item in the ListView larger.
I'm not sure what to post, but I think the layout xml files are the issue.
Here's activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout android:id="#+id/LinearLayout01"
android:layout_height="wrap_content" android:orientation="horizontal"
android:layout_width="fill_parent" android:gravity="center_horizontal"
android:layout_marginTop="2dip" android:background="#669900">
<!--
Use layout_weight to stretch the EditText and compress the button.
To avoid text wrap, the editable text is forced to occupy only one
line
-->
<EditText android:layout_width="wrap_content"
android:typeface="normal"
android:layout_weight="1" android:lines="1" android:ellipsize="middle"
android:hint="#string/hint" android:id="#+id/search_key" android:layout_height="fill_parent" android:maxLines="1"></EditText>
<ImageButton android:layout_width="wrap_content" android:src="#drawable/ic_menu_search" android:adjustViewBounds="true"
android:layout_weight="0" android:id="#+id/btn_ok" android:layout_height="wrap_content"></ImageButton>
</LinearLayout>
<TextView android:layout_height="wrap_content" android:id="#+id/tweet_header"
android:gravity="right" android:layout_width="fill_parent" android:paddingRight="4dp"
android:background="#99cc33" android:textColor="#000000" android:textSize="21dp"></TextView>
<ListView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="#+id/tweet_list"></ListView>
</LinearLayout>
And the ListView is made up of this item.xml
<?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">
<ImageView
android:id="#+id/itemImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:scaleType="fitCenter"
android:src="#drawable/ic_launcher" />
<TextView
android:layout_height="wrap_content"
android:id="#+id/created_at"
android:text="now"
android:textSize="10sp"
android:layout_below="#id/itemImage"
android:layout_alignParentRight="true"
android:textStyle="italic"
android:layout_width="wrap_content"></TextView>
<TextView
android:id="#+id/itemURL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="itemURL"
android:visibility="invisible" />
</RelativeLayout>
So the app does this: It taps ebay for car data and presents the search results as line 1 with a picture, line 2 with the ebay item title. A hidden value is the URL so users can tap the ListView line and launch a web browser.
Looks like the wrap_content setting for the ImageView's layout_width and layout_height are the issue. When I switched that to numerical values, suddenly I saw it change size. Finally setting it to 100dp made the images viewable.
As an aside, I had a terrible time with ADS and the emulator. It consistently failed to re-load my updated app. Often complaining about the Package Manager and suggesting the some process was running. I little idea what was running and how to fix it. When I switched to loading the app straight to the phone, then it worked fine.
So, I think now I need to create a system that is proportional, and takes in to consideration the displaying devices resolution.
Problem is the Relative Layout width being wrap_content. Try changing that to match parent. then you would not have to go thru this ordeal

Why is the Android activity weirdly zoomed in?

I am running the app on Galaxy Note, which is hdpi. And I got all the drawables (drawable-hdpi, drawable-mdpi etc.) correct. But the page (activity) is weirdly zoomed in like this:
You can notice that the cursor icon, top header and the background tiles are larger than normal.
It is supposed to be like this:
The layout file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#drawable/bg_app"
>
<EditText android:id="#+id/content"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:inputType="textMultiLine|textCapSentences"
android:textColor="#000"
android:textSize="18sp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:gravity="top|left"
android:padding="10dp"
android:layout_margin="10dp"
android:lineSpacingMultiplier="1.1"
android:minLines="3"
/>
</LinearLayout>
you need to add the following to the manifest
the tag "uses-sdk" with android:minSdkVersion="8" (it might work with 7 I did not test)
:-)
Problem solved by using
<uses-sdk android:minSdkVersion="4" />
in AndroidManifest.xml

ImageView source will not scale

This should be easy, but I could not find a solution. I have three ImageViews inside a RelativeLayout. These ImageViews will represent three buttons (I tried using ImageButton as well, same problem there).
Thing is, the three sources, bluered, green and blueyellow are *.png files of some size (in this case larger than the buttons/ImageViews size). I want these sources to scale to fit into the ImageViews and use the dimension of buttonsleftRightMenu. The sources are quadratic images, so this should be easy. Where do I go wrong?
xml file:
<?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="match_parent"
android:id="#integer/leftMenuID"
>
<ImageView
android:layout_width="#dimen/buttonsLeftRightMenu"
android:layout_height="#dimen/buttonsLeftRightMenu"
android:src="#drawable/bluered"
android:id="#integer/leftMenuButton1ID"
android:clickable="true"
android:contentDescription="#string/leftMenuButton1ContentDescription"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
/>
<ImageView
android:layout_width="#dimen/buttonsLeftRightMenu"
android:layout_height="#dimen/buttonsLeftRightMenu"
android:id="#integer/leftMenuButton2ID"
android:clickable="true"
android:src="#drawable/green"
android:background="#color/transparent"
android:contentDescription="#string/leftMenuButton2ContentDescription"
android:layout_below="#integer/leftMenuButton1ID"
android:scaleType="fitCenter"
/>
<ImageView
android:layout_width="#dimen/buttonsLeftRightMenu"
android:layout_height="#dimen/buttonsLeftRightMenu"
android:id="#integer/leftMenuButton3ID"
android:clickable="true"
android:src="#drawable/blueyellow"
android:background="#color/transparent"
android:contentDescription="#string/leftMenuButton3ContentDescription"
android:layout_below="#integer/leftMenuButton2ID"
android:scaleType="fitCenter"
/>
</RelativeLayout>
This was just a stupid mistake. The code works perfectly, just remember to inflate the corrext xml file.

1x1 size Nine-patch image not showing up on Android emulator device

I'd like to use a 1x1 size Nine-patch image from Android drawable resources.
When I'm trying to display it with <ImageView> in my layout xml file, this one is never showing up on the Android emulator device. Here's the xml code below:
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10px"
>
<RelativeLayout
android:gravity="center_vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:id="#+id/text_label"
android:text="#string/text"
android:textSize="10pt"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<CheckBox android:id="#+id/my_checkBox"
android:layout_alignBaseline="#id/text_label"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
<ImageView android:paddingTop="10px"
android:paddingBottom="10px"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:src="#android:drawable/divider_horizontal_bright" />
</LinearLayout>
I tried another one with the same size and I have the same problem it's still blank.
My research on Google was irrelevant. Hope you can find what am I doing wrong here.
Thanks in advance for your help.
Lorenth
What version of the SDK are you writing for?
Take a peek at the divider_horizontal_bright.png files in the different versions :)
It's 99% transparent in 8, but like 50% transparent light grey in 4.
Or, Perhaps you meant divider_horizontal_bright_opaque?
This works for me:
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#android:drawable/divider_horizontal_dark"
android:scaleType="fitXY"
/>

Categories

Resources