How can I achieve this (or something like this)?
Looking for some 'underlines' that will be the width of the element.
Was thinking a drawable but I'm not too sure how that would work with stretching and what not. Thanks.
Edit
Made a new XML file and included it under every title, works great.
<merge xmlns:android="http://schemas.android.com/apk/res/android" >
<View
android:id="#+id/layout_underline"
android:layout_width="match_parent"
android:layout_height="3dip"
android:background="#color/layout_underline" />
</merge>
you can get it by create view in XML as below :
<View
android:layout_width="fill_parent"
android:layout_height="2dp" />
and you can customize it as you need,
hope help you
Create a 9-patch image and set it as the background of your TextViews.
Here's the 9-patch resource page: http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch
Related
I am having some weired problem with 9-patch image in my android app.
I want to make a line across a screen with a simple png. After creating 9-patch from it I've simply added it as a drawable to ImageView container. Unfortunatelly it doesn't want to stretch and still has this same dimmensions. Because I've never used 9-patch png I have no idea what am I doing wrong and also searching in Google is not so helpful, because there are only info, how you can make one, now how you can use it.
This is my code fragment from xml file:
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/testpng" />
and this is a image I want to add:
Well, if it's just a simple line,you wouldn't need a 9 patch...
Just use a View, give it a color as a background and give it a 1 px dimension:
<!-- Horizontal line -->
<View
android_layout_width="match_parent"
android_layout_height="1px"
android:background="#ffff"
/>
<!-- Vertical line -->
<View
android_layout_width="1px"
android_layout_height="match_parent"
android:background="#ffff"
/>
For the Shadowed line:
I'm using it so:
<View
android:layout_width="match_parent"
android:layout_height="2px"
android:layout_centerVertical="true"
android:background="#drawable/line_h"
/>
and this is line_h.9png, as small as I could make it (6*4 px) ;)
Now, this doesn't show in my graphical layout editor, but it does at run time!
Check that the extension of your file is .9.png. If it isn't, it's not recognized as a 9-patch.
I found an answer to my question. The missing thing was one line of code android:scaleType="fitXY".
Now it looks like this
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="#drawable/testpng" />
I am new to android and I made an auto - complete textview and it is working , but my problem is the text size in the android.R.layout.simple_dropdown_item_1line is bigger than simple_dropdown_item_1line .
So is there a way that I can set the text size or set the size of the android.R.layout.simple_dropdown_item_1line ? .
Thanks in advance
Create a custom layout, or copy android.R.layout.simple_dropdown_item_1 contents create a new xml and pass this xml to AutoCompleteTextView
sample:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/autoComplete"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="10sp"
/>
</LinearLayout>
srikanth gr's answer is outdated. This answer is best.
What is "android.R.layout.simple_list_item_1"?
A link to the file in github is:
https://github.com/android/platform_frameworks_base/blob/master/core/res/res/layout/simple_dropdown_item_1line.xml
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
In my application, I want to set bubbles to a text view, in the text view I add the setBackgroundResource() as you can see in the code.
With this code i'm getting an image like this:
I want a bubble shape image like this:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#EDF5E4" />
<corners android:bottomLeftRadius="#dimen/corner_radius"
android:bottomRightRadius="#dimen/corner_radius"
android:topLeftRadius="#dimen/corner_radius"
id:topRightRadius="#dimen/corner_radius" />
Please tell me how to make this in my setBackgroundResource() XML.
What you need to use is essentially a 9-patch image (As already pointed out by Ken Wolf in this comment).
To get you started, I am including a set of 9-patch images from one of my apps along with a brief piece of code on how to use it when creating a layout XMl. ;-)
The 9-patch Image Set:
(These are named: bubble_white_normal_mdpi.9, bubble_white_normal_hdpi.9 and bubble_white_normal_xhdpi.9 respectively. Remove the _mdpi, _hdpi and _xhdpi from the file names after placing them in their respective drawable folders.
The XML:
<LinearLayout
android:id="#+id/linlaUserOther"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:baselineAligned="false"
android:orientation="horizontal"
android:padding="2dp" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="top|center" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="#+id/imgvwProfileOther"
android:layout_width="42dp"
android:layout_height="42dp"
android:adjustViewBounds="true"
android:contentDescription="#string/content_desc_user_profile"
android:scaleType="centerCrop"
android:src="#drawable/ic_contact_picture" >
</ImageView>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#drawable/bubble_white_normal"
android:gravity="top|center"
android:orientation="vertical" >
.... // OTHER STUFF HERE THAT IS NOT NECESSARY IN THIS CODE SNIPPET ON SO
</LinearLayout>
</LinearLayout>
NOTE 1:
Although, I am including a working set of Images (almost spoon feeding, if you will), I would strongly urge you to create your own set of images that fit in your scheme of things. Plus, this will also equip you to build your own resources in the future. The only reason I am going the extra mile is because I personally lost 3 days getting the speech bubble looking and working right. :-(
NOTE 2:
I am setting the image as a background to a LinearLayout. You, however, will need to set it to the TextView you need looking like a Speech Bubble.
Additional Sites (Tutorials):
http://blog.booleanbites.com/2012/12/android-listview-with-speech-bubble.html
https://github.com/AdilSoomro/Android-Speech-Bubble
http://developer.android.com/reference/android/graphics/NinePatch.html
http://developer.android.com/tools/help/draw9patch.html
I think you are going to have a hard time trying to do it using just shape drawables.
I would use a 9-patch png.
http://developer.android.com/reference/android/graphics/NinePatch.html
Basically you either find/buy an image or create one in your favourite drawing program. Then you define the stretchable regions using the draw9patch tool which allow it to scale properly in your View.
Here is a tutorial, it's even specific to speech bubbles!
http://adilsoomro.blogspot.co.uk/2012/11/android-how-to-use-9-patch-png.html
It takes a bit of time but it is a crucial technique in making more designed visual interfaces.
I am a new one in Android so please sorry for stupidity.
Well my problem is in multiple layers -
I would like to combine two transparent ImageViews one above the other. This is similar to photoshops layers, what is the sample layers activity in android?
You can use a RelativeLayout for this.
The property android:layout_centerInParent If true, centers the child horizontally and vertically within its parent. [boolean]
Similarly there are properties like ,
android:layout_alignParentLeft,
android:layout_alignParentRight,
android:layout_alignParentTop,
android:layout_alignParentBottom.
Try these.
Already answered Overlapping Views in Android ? That should be all you need, using RelativeLayout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/layout"
>
<ImageView android:id="#+id/imageview1"
android:background="#00000000"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/image1"
/>
<ImageView android:id="#+id/imageview2"
android:background="#00000000"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/image2"
/>
</RelativeLayout>
would be an example code for you.
you can use the layer-list, for a full investigation, please refer to http://developer.android.com/guide/topics/resources/drawable-resource.html#LayerList
Well its quite possible to do in android, but the thing is what actually you are going to do with that. you can give the same positions for both the images in layout now both will be overlapped and based on your condition or situation you can show and hide one another programatically. In the same way you can give multiple images overlapped on one another. Hope this will help you out to understand :)