Android Studio XML Widgets not rendering properly in designer - android

Recently, while working on some projects, I've had a rather annoying problem when coding the user interface of my application. The problem is, some controls (usually a floating action button or a regular button) render strangely. It's hard for me to explain exactly how it looks - but here's an example of how it shows the floating action button to look like in the designer:
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:baselineAligned="false"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
tools:context=".MainActivity">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:src="#drawable/ic_baseline_add_24"
android:layout_height="wrap_content"/>
</LinearLayout>
Now, the thing is, I don't have any weird or special code added, the XML code is as pure as it gets, so I have no idea why I am having these strange rendering problems.
Here is how it rendered the following button:
Code:
<com.google.android.material.button.MaterialButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Submit"
android:layout_gravity="bottom"
android:textAllCaps="false"
android:layout_margin="30dp"
app:cornerRadius="30dp"
android:id="#+id/submitButton"
android:backgroundTint="#color/turquoise"
/>
Image:
A solution would be greatly appreciated!
Cheers,
Tom

Solution is simple u just need to restart your android rendering engine. I provided Image for your context . In android studio top right corner above layout display there is Toggle issue panel click on that and u will see one box in the bottom showing rendering issue restart rendering engine and that will restart your android studio. and u good to go. try this solution and let me know your issue is solved or not.
note: In my Image I already restarted so there is no option for restart rendering engine .but in yours's U may be find hope so.
Image

Related

Android nested layout

I am developing my first Android app. Although I have 15 years of Java software development experience, Android is new to me. My desired look is a background image with other images on top of it, as well as labels and phone numbers. It seems like the best way to accomplish this is a Linear Layout for the background image, with a nested layout for the other fields on top of that. I have searched online and cannot find any sample code on how to accomplish this. Any recommendations would be greatly appreciated. Thanks in advance.
What are you using to develop? If you are you using Eclipse with the Android SDK this is super easy. Put the desired picture in the appropriate drawable folder, go to the graphical view of layout that corresponds to your activity, on the right side of the screen there is a list of all the properties, find background, then select your picture from drawables. You can also do this from the xml using android:background="#drawable/yourPic". This way you don't have to worry about having things layered on top of it.
I think you should go through followings:
1. http://phandroid.com/2011/05/11/10-tips-for-android-ui-design/
2. http://mobile.tutsplus.com/series/android-user-interface-design/
3. http://coding.smashingmagazine.com/2011/06/30/designing-for-android/
4. http://android-developers.blogspot.in/2011/09/thinking-like-web-designer.html
If I got, something like this can work:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<stuff>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<stuff>
</RelativeLayout>
<stuff>
</RelativeLayout>
I used it in an app, and made the trick.
First of all, RelativeLayout is the best layout to use. It depends on your design.
If your design says to keep all the views either vertically OR horizontally, you can use LinearLayouts in between.
My suggested way:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout android:id="#+id/layout1"
android:layout_width="match_parent"
android:layout_height="wrap_parent"
android:orientation="Horizontal">
<View1 />
<View2 />
</LinearLayout>
</LinearLayout android:id="#+id/layout2"
android:layout_width="match_parent"
android:layout_height="wrap_parent"
android:orientation="Vertical"
android:layout_below="#id/layout1">
<View3 />
<View4 />
</LinearLayout>
</RelativeLayout>
Which will yield you something like this

xml / linearlayout not showing properly on device

I'm sorry if this question's been asked already but I wasn't able to find any answers. Here's some background context:
I was testing my app on my Nexus 4 to fix some minor bugs. However, just as eclipse was launching it, there was a powercut in the area, switching my computer off. Eventually, once the power restored, I thought I would set a font by .setTypeFace() before running my app again but this made my app crash when I did run it. So after fiddling around with the code and finding no fix, I decided to get rid of the whole font and just run the app with the bug fix. However, this made my app look like this.
Now on eclipse, the graphical layout is showing this. My app before today was showing like the graphical layout perfectly fine. No errors are showing up on eclipse.
Why has this happened and how do I fix this? Could I have corrupted the whole file?
Thanks.
EDIT: the xml file:
<?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:background="#drawable/testbg"
android:orientation="vertical"
android:weightSum="100" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="33" >
---- bunch of textviews ----
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="57" >
---- More Textviews ----
</RelativeLayout>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="10"
android:orientation="horizontal"
android:weightSum="3" >
---- three buttons ----
</LinearLayout>
</LinearLayout>
I finally figured it out - it was the background. I must've obviously messed up the 9.png somewhere because it fixed itself once I got rid of the background.
Normally this happens with my apps when i change the font , some fonts appears like this in the layouts , some play around i use is adding a character or a dot after tab space , and it works , however double check the font issue again ,try to set the font again or to set another font.

Re-creating Google+ app's UI

I'm fairly new to Android development and planning to build a simple news reader app to further familiarize myself to the platform.
The problem is; I want each of the news-item to look like Google+'s post item below:
Well, basically a big headline picture with a title and some description underneath.
I tried to re-create it using a Button (because the whole thing needs to be clickable by the user) while setting a drawable at the top of the text. It worked quite nicely.. until I decided to add more drawables to it:
Here's my XML code (although I doubt anyone would need it):
<?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" >
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/ic_launcher"
android:drawablePadding="8dp"
android:drawableTop="#drawable/temp_jakarta"
android:text="Button" />
</RelativeLayout>
Can you tell me why is this happening or maybe, suggest me another way to accomplish this?
Thanks in advance!
p.s., I'm pretty sorry about the link; as a new user, SO didn't allow me to post images just yet. :(
Put everything inside a RelativeLayout and place one relative to others (event on top, this doesn't matter at all) using the layout_below/above/left_of/right_of/... etc.
See http://developer.android.com/guide/topics/ui/layout/relative.html for usage, http://developer.android.com/reference/android/widget/RelativeLayout.html for a complete reference of the RelativeLayout class and "Android Layout Tricks" series in the Developer Blog for some tips_
http://android-developers.blogspot.com.es/2009/02/android-layout-tricks-1.html
http://android-developers.blogspot.com.es/2009/02/android-layout-tricks-2-reusing-layouts.html
http://android-developers.blogspot.com.es/2009/03/android-layout-tricks-3-optimize-with.html

Slide Toggle for Android

Anyone know of any open source implementation of a slide toggle for android. The default android toggle(ToggleButton) is not pretty. I am looking for anything similar to iOS. I should be able to implement one from scratch. But if anything similar is already available, then i can build on it.
Thanks in advance to the wonderful stackoverflow community.
Edit1:
What I meant by iOS Slide Toggle is UISwitch
Edit2: Just want to summarize the answer. Commonsware provided the clue. I ended up back porting the Switch code from 4.0 to2.2.2. Thanks to the open-sourced code, back porting was not very difficult. The code is hosted on git hub. http://github.com/pellucide/Android-Switch-Demo-pre-4.0/tree/master/
A screenshot from that project
you can use the sliding drawer widget in android to have a sliding toggle switch. you just have to "slice" the ios toggle images into3 parts, one for the handle, one for the sliding drawer background and one for the content part. then put an image on top of it like a frame to give you the "round edges"
here's what i've come up with:
XML Layout
<?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" >
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="100dp" >
<SlidingDrawer
android:id="#+id/slidingDrawer1"
android:layout_width="154dp"
android:layout_height="54dp"
android:background="#drawable/ios_retina_toggle_on_full"
android:content="#+id/content"
android:handle="#+id/handle"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/handle"
android:layout_width="54dp"
android:layout_height="54dp"
android:background="#00000000"
android:src="#drawable/ios_retina_toggle_button" />
<ImageView
android:id="#+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ios_retina_toggle_off" />
</SlidingDrawer>
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ios_retina_toggle_frame" />
</FrameLayout>
</LinearLayout>
ios_retina_toggle_on_full
ios_retina_toggle_button
ios_retina_toggle_off
ios_retina_toggle_frame
and finally a screenshot of how it looked on the emulator on a 3.7 WVGA screen running gingerbread:
iOS does not seem to have a "slide toggle", at least under that name, based on a Google search. And, you did not provide an image (or a link to an image) of what you want.
Android 4.0 added a Switch that you might be able to backport to earlier versions. You will see samples of it in the API Demos app on your emulator:
You can try using ToggleButton specifying your own drawables for its states.
We can try using seekbar with custom drawables and thumb, setting the max value to 1 and min to 0. we can add animations for sliding effect

Android apps button size

am an upcoming android developer. I have my app in eclipse running on 2.2 android platform and the only thing remaining is adding fancy buttons to it. I have designed some buttons using photoshop but my main problem is to get the right dimensions (width, height and pixels) for my button so that they can fit properly on the screen. Please help! Thank you.
lucky for you, android sdk comes with a tool that allows you to adjust which parts of your image can be stretched, and which shouldn't be (as i'm thinking that's what you're worrying about). it's called 9-patch, and you can read about it here
What you have to do is play with your .xml file. You have to adjust your Buttons's properties like width and height and that will do.
Start playing with this for example:
<?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" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:height="50sp"
android:width="100sp"
android:background="#drawable/my_image"
android:text="I'm a button"
/>
</LinearLayout>
I recommend you this reading:
Android Button

Categories

Resources