As I posted here how-can-i-create-layout-for-both-320dp-and-360dp. In that question I gave a simple example about two buttons. But Now I've my layout for 320dp and I couldn't create a layout for 360dp like Motorola Atrix. Because the solution was given was related for LinearLayout and my layout now is Relative. How can I avoid or fill the blank space at right?
layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#drawable/bg_tapfast" >
<ImageView
android:id="#+id/img_logomaior"
android:layout_width="#dimen/default_width_img_logomaior"
android:layout_height="#dimen/default_height_img_logomaior"
android:src="#drawable/img_logomaior"
android:layout_marginTop="#dimen/margin_top_img_logomaior"
android:layout_marginLeft="#dimen/margin_left_img_logomaior"
android:layout_alignParentLeft="true" />
<ImageView
android:id="#+id/img_mode_tapcolor"
android:layout_width="#dimen/default_width_mode_tapcolor"
android:layout_height="#dimen/default_height_mode_tapcolor"
android:src="#drawable/mode_tapcolor"
android:layout_marginTop="#dimen/margin_top_mode_tapcolor"
android:layout_marginLeft="#dimen/margin_left_mode_tapcolor" />
<ImageView
android:id="#+id/img_mode_tapname"
android:layout_width="#dimen/default_width_mode_tapname"
android:layout_height="#dimen/default_height_mode_tapname"
android:src="#drawable/mode_tapname"
android:layout_marginTop="#dimen/margin_top_mode_tapname"
android:layout_marginLeft="#dimen/margin_left_mode_tapname" />
<ImageView
android:id="#+id/img_mode_tapgroup"
android:layout_width="#dimen/default_width_mode_tapgroup"
android:layout_height="#dimen/default_height_mode_tapgroup"
android:src="#drawable/mode_tapgroup"
android:layout_marginTop="#dimen/margin_top_mode_tapgroup"
android:layout_marginLeft="#dimen/margin_left_mode_tapgroup" />
<ImageView
android:id="#+id/img_tap_2be"
android:layout_width="#dimen/default_width_tap_2be"
android:layout_height="#dimen/default_width_tap_2be"
android:src="#drawable/tap_2be"
android:layout_alignParentBottom="true"
android:layout_marginLeft="#dimen/margin_left_tap_2be" />
<ImageView
android:id="#+id/img_bt_howtoplay"
android:layout_width="#dimen/default_width_bt_howtoplay"
android:layout_height="#dimen/default_height_bt_howtoplay"
android:src="#drawable/bt_howtoplay"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true" />
</RelativeLayout>
Motorola Atrix
Samsung Galaxy SII
This might help you
http://developer.android.com/resources/articles/layout-tricks-efficiency.html
and this one http://developer.android.com/resources/articles/layout-tricks-merge.html
You'll have to post your code for me to be sure.
But you should be able to add an attribute like this to your RelativeLayout:
android:gravity="center_horizontal"
EDIT: I think if you put your 3 ImageViews inside of their own layout and set the gravity on the top level parent to be center horizontal it will keep all of your ImageViews in the same position relative to each other, but it will also scoot them over some so they are centered no matter which device you are running on.
something like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
android:background="#drawable/bg_tapfast" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:id="#+id/img_logomaior"
android:layout_width="#dimen/default_width_img_logomaior"
android:layout_height="#dimen/default_height_img_logomaior"
android:src="#drawable/img_logomaior"
android:layout_marginTop="#dimen/margin_top_img_logomaior"
android:layout_marginLeft="#dimen/margin_left_img_logomaior"
android:layout_alignParentLeft="true" />
<ImageView
android:id="#+id/img_mode_tapcolor"
android:layout_width="#dimen/default_width_mode_tapcolor"
android:layout_height="#dimen/default_height_mode_tapcolor"
android:src="#drawable/mode_tapcolor"
android:layout_marginTop="#dimen/margin_top_mode_tapcolor"
android:layout_marginLeft="#dimen/margin_left_mode_tapcolor" />
<ImageView
android:id="#+id/img_mode_tapname"
android:layout_width="#dimen/default_width_mode_tapname"
android:layout_height="#dimen/default_height_mode_tapname"
android:src="#drawable/mode_tapname"
android:layout_marginTop="#dimen/margin_top_mode_tapname"
android:layout_marginLeft="#dimen/margin_left_mode_tapname" />
<ImageView
android:id="#+id/img_mode_tapgroup"
android:layout_width="#dimen/default_width_mode_tapgroup"
android:layout_height="#dimen/default_height_mode_tapgroup"
android:src="#drawable/mode_tapgroup"
android:layout_marginTop="#dimen/margin_top_mode_tapgroup"
android:layout_marginLeft="#dimen/margin_left_mode_tapgroup" />
<ImageView
android:id="#+id/img_tap_2be"
android:layout_width="#dimen/default_width_tap_2be"
android:layout_height="#dimen/default_width_tap_2be"
android:src="#drawable/tap_2be"
android:layout_alignParentBottom="true"
android:layout_marginLeft="#dimen/margin_left_tap_2be" />
<ImageView
android:id="#+id/img_bt_howtoplay"
android:layout_width="#dimen/default_width_bt_howtoplay"
android:layout_height="#dimen/default_height_bt_howtoplay"
android:src="#drawable/bt_howtoplay"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true" />
</RelativeLayout>
</RelativeLayout>
Related
I have 2 different layouts.
<ch.yourclick.kitt.classes.CopyBarVisualizer xmlns:custom="http://schemas.android.com/apk/res-auto"
android:id="#+id/bar_top"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_centerHorizontal="true"
custom:avColor="#D11817"
custom:avDensity="0.0"
custom:avGravity="bottom"
custom:avSpeed="fast"
custom:avWidth="20dp" />
<ch.yourclick.kitt.classes.CopyBarVisualizer xmlns:custom="http://schemas.android.com/apk/res-auto"
android:id="#+id/bar_bottom"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dp"
android:rotation="180"
app:avColor="#D11817"
app:avDensity="0.0"
app:avGravity="bottom"
app:avSpeed="fast"
app:avWidth="20dp"
/>
The second one has a rotation of 180 and has been placed below the first one.
My problem is that the one below, looks like it has been moved a little bit to the right and I have no idea why. This is how it looks like:
As you see, they are not on the same lines.
I have tried to fix the second one with
android:layout_marginRight="1dp"
but that is not doing anything (probably because I am using android:layout_centerHorizontal="true").
How can I fix that?
I could fix that issue by adding RelativeLayout to each of these layouts. So RelativeLayout will be centered and so I can use the attribute android:layout_marginRight for the second layout to move it more to the left.
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
>
<ch.yourclick.kitt.classes.CopyBarVisualizer xmlns:custom="http://schemas.android.com/apk/res-auto"
android:id="#+id/bar_top"
android:layout_width="100dp"
android:layout_height="150dp"
custom:avColor="#D11817"
custom:avDensity="0.0"
custom:avGravity="bottom"
custom:avSpeed="fast"
custom:avWidth="20dp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
>
<ch.yourclick.kitt.classes.CopyBarVisualizer xmlns:custom="http://schemas.android.com/apk/res-auto"
android:id="#+id/bar_bottom"
android:layout_width="100dp"
android:layout_height="150dp"
android:layout_marginTop="150dp"
android:layout_marginRight="2dp"
android:layout_marginEnd="2dp"
android:rotation="180"
app:avColor="#D11817"
app:avDensity="0.0"
app:avGravity="bottom"
app:avSpeed="fast"
app:avWidth="20dp"
/>
</RelativeLayout>
How can i achieve a layout with 2 images in android, one image overlaying another image at the top right?
an image overlapping another image at the top right
http://i.imgur.com/uT3L2wl.jpg
I tried using relative layout, but i could position the overlay image by giving layout margin, but if i do that i cant support all screen sizes with that design.
and also i couldnt position the overlay image with respect to the underimage.
i want to design my layout like the pic i have shared.
I could get this working from the below code,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/main1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="#+id/c1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" >
<ImageButton
android:id="#+id/addnewcustomer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#id/c1"
android:layout_toRightOf="#id/c1" >
</RelativeLayout>
<ImageButton
android:id="#+id/hover1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/c1"
android:layout_alignLeft="#+id/c1"
android:layout_marginBottom="23dp"
android:layout_marginLeft="22dp"
android:background="#null"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
Try look at FrameLayout. It will do the job.
http://www.learn-android-easily.com/2013/05/frame-layout-in-androis.html
I am develop xml with some image button,image buttons show properly in emulator but it Disorganization on
devices(for example galaxy fit)
As described in emulator https://www.dropbox.com/s/qeecp868ht61sck/emulator.jpg and galaxy fit https://www.dropbox.com/s/23r9tvtp0tcn7bs/fit.jpg
what change imagebutton Proportional to size device?
what can i do?
this is my xml:
<RelativeLayout 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"
tools:context=".Main"
android:background="#drawable/backmain" >
<ImageButton
android:id="#+id/btnfehrest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="53dp"
android:background="#null"
android:src="#drawable/fehrest" />
<ImageButton
android:id="#+id/btndarbareh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/btnfehrest"
android:layout_marginLeft="21dp"
android:background="#null"
android:src="#drawable/darbareh" />
<ImageButton
android:id="#+id/btnmahsulat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/btndarbareh"
android:layout_marginRight="17dp"
android:background="#null"
android:src="#drawable/mahsulat" />
<ImageButton
android:id="#+id/btnkhoruj"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/btndarbareh"
android:layout_centerHorizontal="true"
android:background="#null"
android:src="#drawable/khoruj" />
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/main"
android:scaleType="fitXY" />
</FrameLayout>
</RelativeLayout>
It is all because you are using Relative Layout in your xml
Relative layout always maintains a relationship with other views in your xml either with Parent view or with child views.
so on small screen your FrameLayout with button image trying to fit in the screen as it maintaining the relationship with other views, that's why its overlaping.
Talking about giving the suggestion regarding this.
1) You can use Linear Layout with scroll view, ie if views gets out of screen you can see them by scrolling down.
//If you don't wanna do this
2) You can create another xml in layout-small with same name.
Example:
res> layout> main.xml
and
res> layout-small> main.xml
Second option will help you in creating multi support for different screen sizes.
Note: By Default layout-small folder is not present but you can create it.
I've got an activity layout specified in an XML file - activity_intro.xml - and I'm trying to create another one that is similar but slightly different - that's going to be activity_instructions.xml.
The Intro activity has a 9patch image at the bottom of the screen that is supposed to stay there and only adjust to different widths of the screens.
The Instructions activity is supposed to contain the same image but above 2 more buttons - all three of these views need to be always located at the bottom of the screen.
activity_intro.xml:
<?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:orientation="vertical" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#drawable/home_background" >
<LinearLayout
style="#style/Activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/introAnimationImageView"
android:layout_width="152dip"
android:layout_height="176dip"
android:layout_gravity="center_horizontal"
android:contentDescription="#string/intro_animation_content_description"
android:src="#drawable/animation_intro01" />
<TextView
android:id="#+id/introTextViewTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/intro_title"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/introTextViewSubtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/intro_subtitle"
android:textAppearance="?android:attr/textAppearanceMedium" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/introButtonLoginSignup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="#string/intro_button_label_login_signup" />
<Button
android:id="#+id/introButtonInstructions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/introButtonLoginSignup"
android:text="#string/intro_button_label_instructions" />
<Button
android:id="#+id/introButtonReportAnonymously"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/introButtonLoginSignup"
android:layout_centerHorizontal="true"
android:text="#string/intro_button_label_report_anonymously" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:contentDescription="#null"
android:scaleType="fitXY"
android:src="#drawable/footer_cityscape" />
</LinearLayout>
Result:
Since I've got working code for Intro, I wanted to make Instructions follow its example but the layout_weight property isn't behaving as expected. First of all, I was only trying to put in the 2 buttons and leave out the image:
<?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:orientation="vertical" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="0.1"
android:background="#drawable/home_background" >
<LinearLayout
style="#style/Activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/instructionsTextViewTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/instructions_title_1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<ImageView
android:id="#+id/instructionsImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/instructions_image_content_description"
android:src="#drawable/forms" />
<TextView
android:id="#+id/instructionsTextViewDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/instructions_description_1"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<Button
android:id="#+id/instructionsButtonPrevious"
style="#style/ButtonPrevious"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="#string/instructions_button_label_previous" />
<Button
android:id="#+id/instructionsButtonNext"
style="#style/ButtonNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="#string/instructions_button_label_next" />
</RelativeLayout>
</LinearLayout>
This only worked when I set the layout_weight of the bottom RelativeLayout to 1 (instead of 0) and for the ScrollView 0.1 (instead of 1). If I used the original values the RelativeLayout would take up all the screen. Could anyone explain to me why that is?
I also tried googling the issue and noticed people would suggest to set layout_height to 0dip which I tried but it also didn't work as expected.
Secondly, I tried adding the already mentioned ImageView to the bottom RelativeLayout. This, however, basically displays only the ImageView and not the buttons - or one of the buttons is on top of the image (hiding it). Why is that? Don't I specifically set the buttons to be placed below it?
What should the code look like in order for it to be doing what I expect it?
Further explanation:
Below are images that should help indicate what exactly I want to achieve. The green bits are the ScrollViews - I added them because Android devices tend to have diverse screen sizes. Their purpose is to present the content properly independently of the screen size, i.e. if the screen is small, the user will be able to scroll that part to read the entire text and view the image.
The red bit on the left (Intro) shows the ImageView that is supposed to always be at the bottom of the screen; it'll always be there, visible, and it's the green bit above it that will be movable.
If you take a look at the red bit on the right (Instructions), there's a Next button that's covering the image with the lorry/truck that was visible in the Intro screenshot. Now that's wrong - there should be 2 buttons BELOW the image, as seen on the last screenshot (the 2 blue rectangles).
This is my layout file is ::
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="#+id/relativeLayout1"
android:layout_width="wrap_content" android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#drawable/bg1"
>
<!-- <RelativeLayout android:id="#+id/relativeLayo"
android:layout_width="480dp" android:layout_height="320dp"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_marginLeft="20dp"
android:background="#drawable/bg1"> -->
<ImageView android:src="#drawable/lets_play"
android:layout_width="wrap_content" android:layout_marginLeft="260dp"
android:id="#+id/imageView1" android:layout_height="wrap_content"
android:layout_marginTop="40dp"
></ImageView>
<ImageView android:src="#drawable/show_me"
android:layout_width="wrap_content" android:layout_marginLeft="220dp"
android:id="#+id/imageView1" android:layout_height="wrap_content"
android:layout_marginTop="60dp"
></ImageView>
<ImageButton android:id="#+id/anim_btn_play"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="260dp" android:layout_marginTop="150dp"
android:src="#drawable/play">
</ImageButton>
</RelativeLayout>
And mobile output is like ::
![this][1]
now my problem is :: i would like to set 480 * 320 size screen and layout is starting from left. At right side there is black portion remain.i have approx ten activity and all activity are going to display same direction. now i would like to show in center like ::
![this][2]
so can you tell me solution?
Easiest method is to wrap your Relative layout with something else, probably linear layout would be fine, and then:
<linearlayout gravity=center>
<relativelayout width=480dp height=320dp>
...
It should quick fix your problem on particular 480x320 screen.
BUT, I would suggest you rethink about your background image to make it possible to adopt to screens with different aspect ratio, consider looking nine-patch and make the background 'strecthable' or make a custom drawable that will stay in middle of screen.