Android xml design issues in version 4.1.2 - android

I am working with android tablet's. which has now design issues in various version of android which is looking good in some version's and not looking good in some version's(xml layout designs).
i deployed my app in two different version(4.1.2 and 4.4.2) with same screen size 10 inch
But the result is not same since the design is somehow changed, Checkbox text is not aligned properly in 4.1.2 but 4.4.2 looks better as i expected..
What is the problem in my coding? i have attached the screenshot below and see the checkbox coding for the reference.
<CheckBox
android:id="#+id/rememberme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingLeft="20dp"
android:button="#drawable/checkboxstate"
android:layout_marginRight="50dp"
android:paddingTop="10dp"
android:text="Remember me "
android:textColor="#000000" />
Helps Appreciated.!

Checkbox padding behaves differently before/after API 17. See this answer for a quick example of how to work around this. The same question contains more discussion of the underlying cause if you are interested.

Related

Correct way of applying material design to checkbox on old devices

I have a checkbox that on Lollipop devices looks like material design guildelines suggest. However, when I open this check box on old android devices, it looks like a default checkbox there.
What is the right way of making sure ALL standard components look on old (14+) android versions same as in Lollipop?
Use support libraries and android.support.v7.widget.AppCompatCheckBox
<android.support.v7.widget.AppCompatCheckBox
android:id="#+id/checkbox_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/white"
/>

In Android 2.3.x text is not showing in two lines

Here is my code :
<TextView
android:id="#+id/text_view_title"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_margin="5dp"
android:ellipsize="end"
android:maxLines="2"
android:textSize="#dimen/text_size_small" />
In Android version 2.3.2, text is not showing in two lines, while in higher version device the text is showing in 2 lines. Also when I remove the tag ellipsize then text will be shown in 2 lines. How can I solve this issue?
Remove the ellipsize tag. If you really want it for higher versions, add it programatically when you inflate the layout for android versions above 2.3.
Alternatively, use different layouts for 2.3 and before vs 3.0 and later. But that's more likely to lead to maintenance bugs. If this is the only difference I wouldn't go that route.

android - best way to place objects / design an activity

So I received a graphic interface for an application I'm building. It has some images and texts and the images are set in a specific way, and some text goes inside or on top some images.
In the android project I opened I get the default activity which is RelativeLayout, but it's hard to set all the elements exactly where they should be with the designer and editing the XML directly seems like a pain.
I also see that elements that I add always "align" to something or right/left to some other element - but what I really want to do is place them at a specific location (so the end result will be the same as the design I got). If I was building it for the web I would have used absolute positions.
What is the correct way to go about this in android?
Thanks
EDIT
I managed to start implementing some elements of the design in a manner that makes them look ok on the eclipse Graphical Layout and on my device.
Is this XML ok - or am I using it wrong:
<ImageView
android:id="#+id/imgClouds"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:contentDescription="#string/layout_activity_main_imgClouds"
android:scaleType="centerCrop"
android:src="#drawable/clouds_ltr" />
<ImageView
android:id="#+id/imgBaby"
android:layout_below="#+id/imgClouds"
android:layout_width="50dp"
android:layout_height="52dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="5dp"
android:layout_marginTop="75dp"
android:contentDescription="#string/layout_activity_main_imgBaby"
android:src="#drawable/baby" />
<ImageView
android:id="#+id/imgBubble"
android:layout_toLeftOf="#+id/imgBaby"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="false"
android:layout_alignParentTop="false"
android:layout_marginLeft="56dp"
android:layout_marginTop="-5dp"
android:layout_marginRight="5dp"
android:src="#drawable/bubble_ltr" />
</RelativeLayout>
This is primarily opinion based, but there's certain things most android developers will agree, "Absolute Position" is not an option in Android, because of the OS Nature like Fragmentation in Device Screen Sizes/Densities, having an absolute position of the elements will lead to a crappy app, it will look good only in the device you are using and chances are that all the other devices will not look as you expect, you really need to look at the android design patterns and best practices to avoid a terrible GUI implementation, RelativeLayout is the best way to go, in android you must learn to love it...
Also the sooner you get used to work with XML directly in layouts will be better for you, most IDEs that help out with this functionality end up adding a lot of unnecessary code, once you go through the learning curve to build layouts using XML it totally worth it.
Hope it helps!
Regards!

Widget changed appearance with 4.4

I have a very basic widget with two buttons in a layout. They look like standard android buttons, but with the 4.4 update the buttons now appear as a dark grey instead of light grey. They remain normal in previous versions of android. Does anyone have any idea of why this is happening and how I can fix this?
Thanks!
Button xml:
<Button
android:id="#+id/button_widget_newshift"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:text="#string/new_shift_split"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#101010"
android:textSize="#dimen/widget_text" />
I don't have an answer (and I don't have enough of a reputation to post a comment). I have the same problem, although I'm creating my buttons in code. They work on devices prior to 4.4, but are dark grey and borderless on my Nexus with 4.4 and a 4.4 emulator.
I understand that 4.4 changed drawables to tone down touch feedback (see http://developer.android.com/design/patterns/new.html). Perhaps, in the process, a button style or drawable got misplaced. If so, a solution/kludge might be to copy working resources from the SDK into your project and call setBackgroundResource() to them. I haven't tried this; I'm hoping someone can come up with something more elegant and definitive.

Custom Checkbox Shows Different layouts for 2.3 and 4.2

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.

Categories

Resources