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
Related
I'm trying to implement something to change between images in ImageView, like a image gallery.
I have this XML to show the ImageView
<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:orientation="vertical">
<HorizontalScrollView
android:id="#+id/hsv_ScrollImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="none">
<ImageView
android:id="#+id/id_imgFinal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</HorizontalScrollView>
</LinearLayout>
My app show images that are in landscape mode, and this is the reason which I am using the HorizontalScrollView. Now I have the problem, I would try to implement something to change to other Image with some kind of gesture, but i don't know if the HorizontalScrollView is a problem for this. Can somebody help me with this? Which method is the most frequently used for this Activities?
Thanks.
Here there is a nice tutorial with a ViewPager. You could even integrate with Gesture-ImageView to add zoom capabilities to the gallery.
Ah! don't forget to add this patch to Gesture-ImageView to better integration.
How about using the Gallery UI widget? It's exactly for scenarios like this. Here's a tutorial for it and the reference.
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 :)
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
I have the following layout:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#EAEAEA">
<ListView
android:id="#+id/xxx"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textColor="#464C59"
android:divider="#A4C539"
android:dividerHeight="1px">
</ListView>
<ImageView
android:id="#+id/home_bottom_bar"
android:src="#drawable/bottombar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:clickable="true"/>
</FrameLayout>
The goal is to have some sort of advertising bar at the bottom of the activity (which contains a list of items). It works ok, except for one thing! There is some sort of extra space just under the bar (it's very small but it's noticeable enough). By the way, all the paddings are set to 0 so where does this space come from?
Thanks!
EDIT
After investigating the issue, it turns out that the custom background (#EAEAEA) is causing this extra space. Still don't know how to fix this though.
When you mention that it is a small extra space, it may be the tiny gradient at the top and bottom. Created by ListView, when it is made scrollable.
You may read about ListView Backgrounds, this should give you the idea on how to fix it, if it is caused by this special gradient.
This gradient line can apparently also be removed: extra line in tab host
You may want to use the merge tag since every activitys base layout is a FrameLayout.
(This may cause the padding. Im not 100% sure on this one though)
Look here.
For some reason, whenever I scroll through my list of items, the background inside my listview disappears and reappears giving rise to a "flicker" effect which I don't really want. I've tried the suggestion at: How to make a ListView transparent in Android? but it doesn't work for some reason. Any suggestions?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/screenLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:background="#color/title_background"
android:text="#string/whatsnew_title"
>
</TextView>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
</ListView>
</LinearLayout>
Did you include android:cacheColorHint="#00000000"? It's the most important part of the proposed fix. I've just tried your code (obviously not an exact reproduction, as you're using references to project-specific resources) with it, and it seems to work.
This post on the Android Developers blog should be of your interest.
This can also be achieved from Java (code) side: listView.setCacheColorHint(Color.TRANSPARENT);
Check your theme.xml for <item name="android:windowBackground">#null</item>. If you have it - remove it. I think one of the popular resources gives this line as example (that's how I got mine).