I have a dialog box that contains an EditText, a RatingBar and two Buttons. The rating bar layout_width has been told to wrap_content, but it spreads out the stars to fit nicely in the space the edit text and the buttons make with their layout parameters. This wouldn't be a problem, but I have told it to increment by half-stars. The selected star value is drawn in real-time by chopping the filled in image, allowing for ratings of whatever fraction of star you want, but it seems the spacing is being included, making my half-stars look like third or quarter stars (especially on lower dpi screens where they make the stars much smaller automatically), while whole stars look fine.
Edit: I've noticed that stars to the left show this symptom far less than stars to the right, in all cases. By which I mean, a half-star on the left may be only slightly off, but a half-star on the right will be the furthest out of all. This happens on all phones I've tested. End edit.
I don't have access to the phone it is most obvious on, but you can still see the effect here:
A picture of a dialog with three full stars, a half star that isn't filled enough, and an empty star http://img534.imageshack.us/img534/1071/device2x.png
The fourth star is not quite filled half way, and it only gets worse on some other phones.
This is my layout xml:
<?xml version="1.0" encoding="UTF-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:padding="10dp">
<EditText android:id="#+id/reviewWriteText"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:ems="13"/>
<RatingBar android:id="#+id/reviewStars"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:numStars="5" android:stepSize="0.5" />
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="horizontal">
<Button android:id="#+id/reviewWriteAccept" android:text="Accept"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1" />
<Button android:id="#+id/reviewWriteCancel" android:text="Close"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</ScrollView>
Maybe you can add this to you manifest file
<uses-sdk android:minSdkVersion="4"
android:targetSdkVersion="7"/>
Or you should change the padding of rating bar.
Related
I'm building layers in Android, for that I'm loading an background image into ImageView with a small mini black boxes drawn over it, like placeholders.
I was wonder how can I set some EditText over those small mini points on the image,you cant see them but suppose I have to black box'x over the bg image and I want to place over them my text1,text2. I tried using RelativeLayout and using fixed padding but when changing the screen size or orientation it get messy, I read that the best thing is to place them on run time by checking the screen resolution and calculating the right sizes for each EditText, but it is to much work I think.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="#+id/background_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/bg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#drawable/bg" />
<TextView
android:id="#+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"/>
<TextView
android:id="#+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"/>
</RelativeLayout>
</RelativeLayout>
This is the Image, and I want to put some text on the black boxes of the result and the team.
What options do I have?
There is lot of device size variation in Android you can't get perfection by doing this, I would recommend you to use plain background of image and take that small mini boxes as different image and set it as a EditText background.
other wise you have to manually set the padding and margin for every devices in which you getting differences.
I hope this will help you.
Padding issue?
Update Sample of the issue:-
(Why is there a gap above the word "Late")
Update 2
Others gave reported similar issues here:- http://code.google.com/p/android/issues/detail?id=22493
So it seems that a textview doesn't reduce in size once it's been bigger. Any ideas for workarounds for this? setting the height explicitly causes the text to be cropped as it's lower than it should be.
I have a layout as follows:-
<?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="wrap_content"
android:padding="1dp"
android:orientation="vertical"
android:background="#color/Green">
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/datetext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textStyle="bold" />
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/DateCode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="40sp"
android:textStyle="bold"
android:background="#color/Red" />
</LinearLayout>
and it is populated into a this GridView to form a calendar:-
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="7"
android:verticalSpacing="2dp"
android:horizontalSpacing="2dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>
The adapter used to populate the gridview with the items changes the text size of #+id/DateCode to fit the text to the width of the available space. it then invalidates the textview and forces a re-layout (I know this works as the bottom of the textview does come up to the bottom of the resized text).
The top of the text within DateCode seems to start at least halfway down the TextView (which is clear as a red box. I don't understand why the area is not shrunk to fit the text in.
I assume it's a padding issue or something I don't understand, but it doesn't seem to be the font padding given how big it is.
Any ideas why the textview is positioning the text so far down, and not wrapping it into a much smaller space?
Anthony
If you are using ADT in Eclipse, then use the Hierarchy Viewer perspective to inspect live Views. That way you can know for sure what is going on with the layout; but to me the two TextViews look suspicious (i.e. where is the other? is it empty?)
Could someone please explain how android uses image button sizes? I seem to be getting odd behavior with my buttons.
I have the following code as an example. I have two buttons that sit at the bottom of my layout. These buttons share 50% of the total width as they sit side-by-side.
Within Abode PS, the two images (used for these two buttons) are actually 2" x 38" or 495x94 pixels. This size is of course larger than the available space in the layout.
I am using edge effects on my buttons to give them definition. Android is cutting the edges off my buttons in order to center then in the available layout space.
This particular layout that I am working on will only allow vertical orientation, in case that helps.
Thank you.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<ImageButton
android:id="#+id/ImageButton1"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_marginLeft="1dip"
android:layout_marginRight="1dip"
android:layout_weight="1"
android:background="#FF000000"
android:src="#drawable/map4" >
</ImageButton>
<ImageButton
android:id="#+id/ImageButton3"
android:layout_width="0dip"
android:layout_marginRight="1dip"
android:layout_weight="1"
android:background="#FF000000"
android:src="#drawable/buy"
android:layout_height="wrap_content"
android:layout_marginLeft="1dip">
</ImageButton>
</LinearLayout>
</RelativeLayout>
Try using an ImageView and android:scaleType:
http://developer.android.com/reference/android/widget/ImageView.html#attr_android:scaleType
Experiment the values available to see what is the best combination!
Then add a listener to behave like a button...
try use the button and make it with empty text after this set the background .
or :
use the image button and put the source and the background the same image to get button exactly like the image
**you can use the selector to make some beauty for application buttons
Google it it's easy to use ;)
I've got a 4-item start screen in my app, which looks like the following:
What's important to me there:
- All items do have the same width (not regarding how much text is actually in it)
- Look the same on all devices (small-screen, mdpi, large-screen, etc.)
Im just wondering if there is a easy solution about this problem?
I've tried using 3 LinearLayouts but thats really awkward..
(1 presenting the layout root[vertical] and two which do each contain 2 buttons[horizonal]).
Making this layout ready for multiple screens would require a lot of fixed-width and fixed-margin hacking. Just like "button margin = 30dp on xlarge, 20 on large, 15 on normal,...".
My layout-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:background="#drawable/background"
android:id="#+id/main_root"
android:orientation="vertical"
android:gravity="center" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center" >
<Button
android:id="#+id/btn_learn"
android:text="#string/mainBtn_learn"
style="#style/mainBtn"
android:onClick="handleBtnClick"
android:layout_margin="20dip" />
<Button
android:id="#+id/btn_quiz"
android:text="#string/mainBtn_quiz"
style="#style/mainBtn"
android:onClick="handleBtnClick"
android:layout_margin="20dip" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center" >
<Button
android:id="#+id/btn_search"
android:text="#string/mainBtn_search"
style="#style/mainBtn"
android:onClick="handleBtnClick"
android:layout_margin="20dip" />
<Button
android:id="#+id/btn_more"
android:text="#string/mainBtn_more"
style="#style/mainBtn"
android:onClick="handleBtnClick"
android:layout_margin="20dip" />
</LinearLayout>
Is there a view which "auto-scales" these Buttons or still any other easier solution?
Edit:
So, in special, you need something like
button:
android:layout_width="15%" // 15% of screen width / height depending on the orientation
android:layout_marginBottom="10%" // see above
I'm pretty new to Android development but I can show you what worked for me in a similar case. I defined my layout as follows:
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="#+id/outputText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:editable="false" />
<Spinner
android:id="#+id/outputSpinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:prompt="#string/OutputBaseOptionsPrompt" />
</LinearLayout>
I have a horizontal layout with two items. The LinearLayout has a width of "match_parent" so that it is as wide as the screen. Both items in the layout have the following:
android:layout_width="0dp"
android:layout_weight="1"
Since both items have a layout_weight of 1, they will be drawn at the same width. In this case, each item takes up half of the available space. If you change the weight of one of these items to "2" then it will be twice as wide as the item with a weight of "1".
Do you already have xml that makes it work on one screen size? If so post what you have so far.
I would suggest using a RelativeLayout for your root though. You can use the alignCenter attributes to float your children towards the middle. Then you just have to hard code the inner margins (how far apart you want the buttons) rather than the margin from yourself to the wall.
You could also avoid having to hard code the inner margin by making your own button 9 patch images. You can just add a border of transparent pixels in your image to represent the margin. You'll probably still want to supply an image for each density you wish to support though.
The solution is you dont use hardcoded values any where
Put three images with same name in hdpi mdpi and ldpi folders in drawables
an run the code
Hey, I have a problem where parts of the Text in the TextView are out of the screen, Look at the picture:
I marked the problem in red squares..
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:layout_gravity="right"
android:background="#drawable/list"
android:padding="15px">
<ScrollView android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="right">
<TextView
android:id="#+id/TfseerTextView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="17px"
android:textColor="#000"
></TextView>
</LinearLayout>
</ScrollView>
</LinearLayout>
Is it possible to fix? Is there any work around? Thanks.
you should use 17sp instead of 17px for your textSize. sp stands for Scaled Pixel, it will result in your app appearing better / more consistent across a wide variety of devices with differing screen sizes and densities.
As for the problem you are having. Does it make any difference if you set the TextViews layout_width attribute to some value e.g. android:layout_width="200dip" It looks to me like your TextView thinks that it has more space to use then it actually does (could be related to the grey box type things you have for the background, but this is a pure guess) If you set it to some specific value and it starts to wrap the text properly on the next line. Then you just have to try a few different widths and find out how big you can make it to keep everything appearing like it should.