I am a newbie to android app development, i am using the ADT with eclipse.
I wrapped all the view components in a scrollbar but when i use the emulator preview i cannot see the scrollbar. The target is a 7inch WSVGA (Tablet).
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/imageDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/test_image_date"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="#+id/Clouds"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/test_image"
/>
<TextView
android:id="#+id/imageDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/test_image_description"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</ScrollView>
No errors have been generated.
Cheers
Ciaran
The scrollview will only be visible if you have enough content that would not fit on the entire screen. Seeing your xml it is possible that you don't have that much of content in the layout
So ran this activity on a Samsung T3 8 inch tablet and the scroll worked fine, couldn't seem to get it on the emulator with a similar simulated device.
Related
I am developing an Android application for school. The layout I worked out looks good for me on the preview of Android Studio, but as soon as I deploy it on my physical device (HTC One m8, Android 5.0.1), everything inside the cardview is messed up.
Layout file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="de.seschi98.trgapp.activities.ScheduleActivity"
tools:showIn="#layout/activity_schedule">
<android.support.v7.widget.CardView
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="120dp">
<GridLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="4"
android:rowCount="1"
android:columnOrderPreserved="false"
android:orientation="horizontal"
android:rowOrderPreserved="false">
<TextView
android:id="#+id/lesson_number"
android:text="01"
android:textSize="22dp"
android:layout_width="wrap_content"
android:layout_column="0"
android:layout_row="0"
android:layout_rowWeight="1"
android:gravity="center_vertical|center_horizontal"
android:textStyle="bold"
android:layout_columnWeight="20" />
<GridLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_column="1"
android:layout_row="0"
android:columnCount="2"
android:layout_columnWeight="90"
android:rowCount="3"
android:layout_height="match_parent">
<TextView
android:gravity="center_vertical|center_horizontal"
android:id="#+id/lesson_name"
android:text="Chemistry"
android:textSize="22dp"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="0"
android:layout_rowWeight="15"
android:layout_gravity="center_horizontal"
android:paddingTop="10dp"
android:layout_width="match_parent" />
<TextView
android:gravity="bottom|center_horizontal"
android:id="#+id/teacher"
android:text="Mr Smith"
android:layout_height="wrap_content"
android:textSize="16dp"
android:layout_column="1"
android:layout_row="1"
android:layout_rowWeight="20"
android:layout_gravity="center_horizontal"
android:layout_width="match_parent" />
<TextView
android:gravity="top|center_horizontal"
android:id="#+id/room"
android:text="Room A-123"
android:textSize="16dp"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="2"
android:layout_rowWeight="20"
android:layout_gravity="center_horizontal"
android:layout_width="match_parent" />
</GridLayout>
<View android:layout_row="0"
android:layout_column="2"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_columnWeight="15">
</View>
<View android:layout_row="0"
android:id="#+id/badge"
android:layout_column="3"
android:layout_height="match_parent"
android:layout_width="0dp"
android:background="#c0392b"
android:layout_columnWeight="5">
</View>
</GridLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
Preview Screenshot
Device Screenshot (don´t matter about the action bar or other stuff, it´s only the CardView...)
// Update: Upgraded my Android version to 6.0.0 Marshmallow yesterday, now it is working fine. But I included the AppCompat thing... What could be the reason for it to not work on previous versions of Android?
Nevermind, it was a version error:
After some testing stuff I realized that I needed to change the <GridLayout> in my layout file to <android.support.v7.widget.GridLayout>. Didn´t think about that cause I thought GridLayout would be compatible with Android 5...
So now it is working fine on all my devices, as well Android 5 as Android 6.
Although it didn´t help me very much, thanks for the fast answers!
The preview in android studio is sometimes different from your device, make sure to set the same screensize of your phone and the preview in android studio
Kenny already gave you the answer.
Sometimes the preview is showing fine but on some devices it looks different. This usually happens because of the screensize and (or) your screen resolution.
You can add an specify layout for a screen size. But you must understand that android runs on an enormous variety of devices and screen sizes. You will always have troubles in some screens, maybe focusing on little design problems is not the way to go.
Check this links:
Android And Supporting Mutiple Screens Layouts
Screens distribution
EDIT:
If you have the same problem in every device then it's probably that isn't about what we've already told. Let me check your code a little more and I'll tell you something else.
Alignment matters, me also had a same problem. I was setting just a single property paddingLeft but in some devices it won't work so I had to provide both property paddingStart & paddingLeft in styles-
<item name="android:paddingLeft">#dimen/drawable_icon_padding_left</item>
<item name="android:paddingStart">#dimen/drawable_icon_padding_left</item>
So make sure you are using both property in your layout or in styles. Happy coding :-)
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
When I run my android application in Android version >=4 I got this out put(I didn't tested in android version 3):
When run the same application in android version 2.3 I got a bit different output:
You can see in second screenshot the image for about button is not visible. But when I try run the same application several times on 2.3 some times I got about image visible.Here is my code :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include layout="#layout/actionbar_with_right_button" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:scrollbars="none" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:drawablePadding="#dimen/settings_text_view_drawable_padding"
android:drawableTop="#drawable/snooze_button"
android:gravity="center"
android:onClick="showRemainderSnoozeSettings"
android:padding="#dimen/settings_text_view_padding"
android:text="#string/snooze" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:drawablePadding="#dimen/settings_text_view_drawable_padding"
android:drawableTop="#drawable/help_button"
android:gravity="center"
android:onClick="showFaq"
android:padding="#dimen/settings_text_view_padding"
android:text="#string/help" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:drawablePadding="#dimen/settings_text_view_drawable_padding"
android:drawableTop="#drawable/about_button"
android:gravity="center"
android:onClick="showAbout"
android:padding="#dimen/settings_text_view_padding"
android:text="#string/about" />
</LinearLayout>
</ScrollView>
I didn't understand why this is happening.
Can anyone help me to solve this issue.
Edit :
One more important thing I forgot to mention when I changed android:drawableTop="#drawable/about_button" to android:drawableTop="#drawable/help_button" of about TextView. It worked perfectly. So it can be an issue of my about_button image. So I recreated the about image again and put in all drawable folder. Even after that also I didn't get any +ve result. This issue only in 2.3 or less.
Thanks
May this help you:
Seems like this is a bug with android, where sometimes the first image in the drawable folder doesn't get displayed.....
I had a similar bug - a particular drawable was not being displayed, no matter in what ImageView. So I Added a dummy image called aaaa.png to the drawable folder and problem was solved....
While developing an Android application I have stumbled upon a baffling problem. The UI element I am creating is a header bar that has a custom search field. Everything looks wonderful on the Android UI editor but the second I use the emulator or a device it bugs out and compresses the magnifying glass image and clips the edit text. I have tried a number of things including changing the background image of the search area to the custom search field that is currently in the parent LinearLayout. This however results in the search field size growing out of control.
Any suggestions are welcome.
My questions are:
1) How would one fix this problem while maintaining the look of the search area?
2) Why is this problem occurring?
Confirmed on the following devices:
Samsung Galaxy Nexus 4.0.2
Motorola Zoom 4.0.3
Nexus S 2.3.7
This is a screenshot of the UI editor:
This is a screenshot of what it looks like on all devices tested:
The XML used to generate these UI elements:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/title_bar_matte"
android:gravity="center_vertical"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_margin="10dp"
android:layout_weight="1.0"
android:background="#drawable/search_field"
android:gravity="center_vertical"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginLeft="15dp"
android:src="#drawable/magnifying_glass" />
<EditText
android:id="#+id/campus_map_acitivity_search"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_marginLeft="10dp"
android:layout_weight="1.0"
android:background="#0FFF"
android:hint="Search"
android:imeOptions="actionSearch"
android:singleLine="true" />
</LinearLayout>
<Button
android:id="#+id/campus_map_activity_goto_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:background="#drawable/button_list" />
<Button
android:id="#+id/campus_map_activity_my_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="#drawable/button_location" />
</LinearLayout>
Just figured out the problem. The search background image had the top and left sides set to 9-patch scale. This is all good and well but we had forgotten to set the bottom and right fill areas so that the content would have room to exist.
http://radleymarx.com/blog/simple-guide-to-9-patch/
Remember to set the fill areas!
It turns out the Android UI editor does not handle 9-patch images like the devices. That seems to be a bug to me.
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"
/>