I am Working on Project with inside i want to Use custome image for Checkbox checked/unchecked event.
inside my login xml i have write :
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="5dp" >
<CheckBox
android:id="#+id/chk_remember_me"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="#drawable/checkbox_uncheked"
android:paddingLeft="5dp"
android:text="Remember Me"
android:textColor="#024d94"
android:textSize="12dp" />
</LinearLayout>
Here i have Used android:paddingLeft="5dp" for getting space between button and textview.
My Problem : i got two different views for 2.3 and 4.2
for Device that has xhdpi or below density or that has large screen i
am getting below screen (this one is perfect as i want ):
for Device that has hdpi or below density or that has normal/small
screen i am getting below screen :
Can anyone tellme where am i missing? or anything Wrong in my layout?
I want the same layout screen which i am getting for 4.2 device in normal/large screen devices.
Thanks in advance.
It appears that Checkbox already uses padding by default internally and overriding it with paddingLeft causes these issues. You should remove that property from your XML.
If you still want to adjust the padding, you will have to do so programatically. See this answer: https://stackoverflow.com/a/4038195/832776
To only apply it to >4.2 you can use the following, though I would test on emulators to make sure this issue isn't merely a problem with just your devices.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
Give the fixed width to check box hopefully this can resolved your problem.
Don't give padding, it comes by default with Checkbox.
Related
First of all I'm quite new in layout development so sorry if this is a noob question.
I'm trying to create an xml with a sort of an interactive background. So I put a background picture and added some ImageButtons with pictures like part of the background layout (to make them invisible).
Everything works as expected but the position of these ImageButtons change from the editor on the base of the device where the app is installed (or the AVD device too). I'm using a constraintlayout.
At the moment, my ImageButtons xml is:
<ImageButton
android:id="#+id/IB1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="83dp"
android:layout_marginTop="14dp"
android:layout_weight="1"
android:background="#android:color/transparent"
android:src="#drawable/IB1"
android:scaleType="fitCenter"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
I understand that this happen because the background picture is resized on the base of the device screen where the app run (and this is in general correct because I want that the background cover all the layout space even if in portrait mode the picture is clearly very bad rendered; think to a tree, when you rotate the phone it is compressed on the vertical side and expanded on the horizontal side).
Exist a way to do what I want? Maybe with another type of layout or with some properties?
Thanks a lot for the help!
I'm developing an Android App that needs to be support Arabic language. (Which should be read from Right To Left). After quick googled the solutions, I figure out android fully support Arabic language natively in API level 17 with the declaration of
android:supportsRtl="true"
in the application tag inside of the AndroidManifest so that I can use the layout mirroring to automatically flip the layout for better right to left reading experience. However, I've noticed there is an issue happening while I use centerInParent in a view that inside of a sub RelativeLayout during the layout mirroring. Below are my codes and expected layout.
<RelativeLayout
android:background="#color/white"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:padding="20dp">
<RelativeLayout
android:background="#drawable/shape_flag_imageview_boarder"
android:id="#+id/imageLayout"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
<ImageView
android:id="#+id/image"
android:layout_height="100dp"
android:layout_width="100dp"
android:visibility="invisible" />
<ProgressBar
android:id="#+id/progressbar"
android:layout_centerInParent="true"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
</RelativeLayout>
<TextView
android:id="#+id/text"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_toEndOf="#id/imageLayout"
android:layout_width="wrap_content"
android:text="Some text here bla bla bla"
android:textColor="#color/black" />
</RelativeLayout>
Image above showing the expected result in normal layout direction which is Left to Right. The purpose I wrap the ImageView and ProgressBar together in a sub view is because I want the ProgressBar showing in the middle of the ImageView while the image is loading from the internet. After the I've changed Locale to Arabic, it becomes like
As I've try and error and figure out that this is causing by the centerInParent of the ProgressBar. It instead of centering inside the sub view, it align center to the root parent view which is the most outer RelativeLayout. Below is the screen shot of removing centerInParent code from the ProgressBar.
It clearly shows the layout mirroring works good, but the ProgressBar position is not what I'm expected. So I've try to work on centerVertical and centerHorizontal, the result are shown in images below respectively.
None of the solutions works, and none of the topic I've searched related to this issue. So I guess this might be a bug from Android library? If anyone knows the issues or solutions, please share to me. Thanks
I fixed it by adding android:layoutDirection="ltr" into the child RelativeLayout. Basically, it deactivates the RTL formatting for this particular RelativeLayout, and the android:layout_centerInParent="true" behaves correctly again. It solves our particular issue as our particular RelativeLayout contains only centred elements. But this trick should not be used if the Layout contains other elements which have to support correctly RTL, like text views for example. Hope it helps.
This is an RTL layout bug in the Android framework, which only affects Android 4.2 specifically (API 17) and when android:supportsRtl="true" is enabled in AndroidManifest.xml.
It happens when you use a RelativeLayout that contains items positioned with android:layout_centerVertical="true" or android:layout_centerInParent="true".
You can fix it in Java code like this:
View relativeLayout = layoutInflater.inflate(R.layout.my_relative_layout, parent, false);
// Fix RTL layout bug on Android 4.2 (for Arabic and Hebrew mode)
if (Build.VERSION.SDK_INT == 17 &&
getResources().getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
// Force a left-to-right layout
relativeLayout.setLayoutDirection(View.LAYOUT_DIRECTION_LTR);
}
let me tell you correct answer, look your RelativeLayout(id:imageLayout),it's width is wrap_content, and your ProgressBar(id:progressbar) add an attribute android:layout_centerInParent="true".It means parent not limit witdh,and child also want to center,so parent will be stretched.
Here's my XML layout example of one of my TextViews which show itself correctly in android 4.2 ... I've downgraded a Nexus S to gingerbread 2.3.6 to test out my application and debug it! Right now, each of my TextViews doesn't take any more space than one line, not even wrapping itself at the end of the first line. (On 4.2, the example below was taking 3 lines and was adding "..." at the end if there was some text missing!)
How can I make my textViews compatible with gingerbread? Thank you!
<TextView
android:id="#+id/TV_guideRow_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/TV_guideRow_title"
android:layout_below="#+id/TV_guideRow_title"
android:text="blabla text that could go up to 3 lines"
android:textColor="#3BB9FF"
android:layout_alignParentRight="true"
android:layout_above="#+id/TV_guideRow_more"
android:layout_marginRight="8dp"
android:layout_marginBottom="3dp"
android:ellipsize="end"
android:maxLines="3"/>
You want:
android:inputType="text|textMultiLine"
Also, depending on the parent of that TextView, multiline may not render properly. Try manually setting the height to, say, 100dp and see if that works.
After some more investigation, I've found out that all my related textView problems were related to my custom theme, which was made for android 4.0+ (since Holo was used as the base theme)
I've set the APIs which doesn't have holo to use the "Light" theme and everything is showing up correctly without any further modification.
Hello stackoverflowers!
This is my button:
<Button
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.30"
android:text="#string/menu_button_newgame"
android:id="#+id/button_newgame"
/>
when I set it's alpha to 150 with
button_newgame.getBackground().setAlpha(150);
it starts looking weird on 2.2! On 2.3.3 the buttons look normally.
Android 2.3.3: (normal)
Android 2.2: (buggy)
What to do ?? :)
It seems to be a problem with the nine-patch.
Try to use
android:layout_height="wrap_content"
All the buttons has the same content and they should keep the same height.
Or try to create a custom nine-patch drawable to use as background.
Can anyone tell me how to reduce the width and height of CheckBox in order to display very small CheckBox in Android ?
Thanks In Advance,
Simply use setWidth(w) and setHeight(h) functions as you would for a normal Button.
setWidth(int) and setHeight(int) since CheckBox extends CompoundButton which extends Button
Try referring to this tutorial
Alernatively try changing it via the XML:
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="new checkbox"
android:background="#drawable/my_checkbox_background"
android:button="#drawable/my_checkbox" />
UPDATE: this only works from API 17 onwards...
As per my answer on this question:
- how can we reduce the size of checkbox please give me an idea
CheckBox derives its height from the TEXT as well as the image.
Set these properties in your XML:
android:text=""
android:textSize="0sp"
Of course this only works if you want no text (worked for me).
Without these changes, the CheckBox was giving me a big margin around my image, as mentioned by Joe