Imagebutton layout_center_inparent problem - android

i am having a problem with my imagebutton it does not align right when i specify the centerinparent.
<LinearLayout
android:layout_width="match_parent" android:layout_marginTop="4dp"
android:layout_marginLeft="4dp" android:layout_marginRight="4dp"
android:layout_height="50dp" android:background="#FF0000">
<RelativeLayout android:layout_height="match_parent"
android:layout_width="40dp" android:background="#0000FF">
<ImageView android:id="#+id/imgType"
android:layout_centerInParent="true" android:layout_width="wrap_content"
android:src="#drawable/type_text" android:layout_height="wrap_content" />
</RelativeLayout>
<RelativeLayout android:layout_height="match_parent"
android:layout_width="match_parent" android:layout_weight="1">
<LinearLayout android:orientation="vertical"
android:layout_height="match_parent" android:layout_width="match_parent">
<TextView android:layout_width="match_parent"
android:textColor="#686a68" android:layout_height="match_parent"
android:textSize="15dp" android:text="Manifest : Text"
android:ellipsize="end" android:singleLine="true"
android:layout_weight="1" />
<TextView android:layout_width="match_parent"
android:textColor="#686a68" android:layout_height="match_parent"
android:textSize="15dp" android:id="#+id/txtTitle" android:text="[TEXT NAME]"
android:layout_weight="1" android:singleLine="true"
android:ellipsize="end" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout android:layout_height="match_parent"
android:layout_width="60dp" android:background="#00FF00">
<ImageButton android:src="#drawable/type_text"
android:layout_height="48dp" android:layout_centerInParent="true"
android:layout_width="48dp" android:id="#+id/butEdit" />
</RelativeLayout>
</LinearLayout>
image
As you can see the vertical alignment of the imagebutton is not right.
why is it doing this.

Have you tried running this on the emulator and using the hierarchyviewer tool (in the "tools" folder of the SDK. Click on your app in the list and select "Load View Hierarchy" ) to inspect the elements in question? Have a look at the margins and padding of both the problem control & its container. Also look at the widths of the various components and it may give you a clue as to where the problem is occurring.
Also check that your drawable in #drawable/type_text does not contain any space around it which could be causing a perceived offset (unlikely, I think).
I have occasionally seen odd problems scaling images, so if #drawable/type_text is not 48x48 pixels, try manually scaling the image to the desired size in Photoshop / GIMP / PSP and see if that makes a difference.
Alternatively try using gravity to try to centre your control:
<LinearLayout android:layout_height="match_parent" android:gravity="center"
android:layout_width="60dp" android:background="#00FF00">
<ImageButton android:src="#drawable/type_text"
android:layout_height="48dp"
android:layout_width="48dp" android:id="#+id/butEdit" />
</LinearLayout>
Or maybe:
<LinearLayout android:layout_height="match_parent" android:gravity="center"
android:layout_width="wrap_content" android:background="#00FF00">
<ImageButton android:src="#drawable/type_text"
android:layout_height="48dp" android:layout_width="48dp"
android:layout_margin="12dp" android:id="#+id/butEdit" />
</LinearLayout>
If all else fails, try tweaking the individual android:layout_margin* attributes of the ImageButton to try and force things.
I hope that some of this helps.

Related

android layout leaving small gaps

So I have a image view and below a relative layout. The desired is to always have the users see the text views and buttons in the nested layout. And the image is a top image ( not a full screen background) but some how there is a small gap and the background of the image is bleed past the image view. I have tried different Image scale types and different layouts completely(frame, all linear,etc..)
http://imgur.com/a/n4aIq
and some code
https://gist.github.com/whatkai/92f66d2322957d86dd3fe28a9a5d03c0
FYI layout-weights left gaps too.
There is too many ways to do it.
Try this solution using LinearLayout (orientation: vertical):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="#+id/REFragment"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="#color/accidentAssistanceColor">
<ImageView
android:id="#+id/SettingsImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:contentDescription="#string/app_name"
android:scaleType="fitXY"
android:src="#drawable/ers"
android:layout_weight="1"/>
<LinearLayout
android:background="#color/appStartERSBackground"
android:layout_centerHorizontal="true"
android:id="#+id/onView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/SettingsImage"
android:gravity="bottom|clip_vertical|center"
android:orientation="vertical">
<Button
android:gravity="bottom|end"
android:layout_centerHorizontal="true"
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#android:color/transparent"
android:text="Not Now"
android:textColor="#color/white"/>
<Button
android:id="#+id/button2"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/button"
android:text="approve"
android:textColor="#color/white"/>
<TextView
android:gravity="center_horizontal|center_vertical"
android:id="#+id/text2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/button2"
android:layout_gravity="center"
android:text="BLdfdsAH"
android:textColor="#color/white"/>
<TextView
android:gravity="center_horizontal|center_vertical"
android:id="#+id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="BLAH"
android:textColor="#color/white"
android:textSize="20sp"
android:textStyle="bold"/>
</LinearLayout>
</LinearLayout>
And to answer you about how to scall your image i used android:scaleType fitXY to respect to ratio aspet.
If you desire to understand how every scallType works, see the following link:
https://robots.thoughtbot.com/android-imageview-scaletype-a-visual-guide
set view tag between your image and layout.
like this.
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#000000" />

RelativeLayout doesn't wrap_content on width on Android 6

I have 2 devices: Asus Zenfone 2 (6.0.1) and Galaxy Note 3 (5.0)
In my app I take photo and on the next screen I show it on ImageView and add some information on it. Here is xml layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true"
android:background="#android:color/black">
<LinearLayout
android:id="#+id/preview_buttons"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible"
android:background="#android:color/black">
<TextView
android:id="#+id/tv_cancel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:textColor="#android:color/white"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:textSize="16sp"
android:text="CANCEL"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#android:color/darker_gray"/>
<TextView
android:id="#+id/tv_accept"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:textColor="#android:color/white"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:textSize="16sp"
android:text="ACCEPT"/>
</LinearLayout>
<RelativeLayout
android:id="#+id/preview_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#android:color/holo_blue_bright"
android:layout_above="#id/preview_buttons">
<ImageView
android:id="#+id/image_preview"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
/>
<TextView
android:id="#+id/preview_top_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingRight="16dp"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:layout_alignRight="#id/image_preview"
android:layout_alignTop="#id/image_preview"
android:gravity="right"
android:background="#drawable/top_text_background"
android:textSize="16sp"
android:textColor="#android:color/white"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginBottom="8dp"
android:layout_alignLeft="#id/image_preview"
android:layout_alignBottom="#id/image_preview"
android:src="#drawable/ic_verified_grey600"/>
<TextView
android:id="#+id/preview_bottom_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingRight="16dp"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:layout_alignRight="#id/image_preview"
android:layout_alignBottom="#id/image_preview"
android:gravity="right"
android:background="#drawable/bottom_text_background"
android:textSize="16sp"
android:textColor="#android:color/white"/>
</RelativeLayout>
</RelativeLayout>
UPD. I have problem with RelativeLayout "preview_container"
From this layout I expect its width would wrap, if ImageView's width doesn't fill whole screen and be on the screen center. And it works nice on GN3, but on my AZ2 I get space at right side (No reputation to insert image, it's here http://i.imgur.com/cSujbAp.png)
UPD2. What I expect: RelativeLayout wraped correctly, so I don't see background. Example from my GN3 here (http://i.imgur.com/vKGQq8r.jpg). Transparent background also can't help because after that I need to get drawing cache of this layout and work with it
I know about alignParent issue, but I don't use it now and my extra views placed correct.
Please help me, what's wrong?
<ImageView
android:id="#+id/image_preview"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
/>
android:layout_height="match_parent" should not be match_parent.
Your preview_top_text has the width set to match_parent so it means that, since her container is the same of the image, it will stretch way to contain also the textview and not only the imageview.
Add the android:layout_centerHorizontal="true" parameter to the imageview and it should be centered.
Hope it helped
UPDATE POINT 2
two possibilities:
change the sizes of the TextViews to wrap_content
change the background of the second relativelayout to transparent

LinearLayout not resizing ImageViews correctly

As part of the on-boarding for my app, I have a series of translucent overlays that highlight the UI. Each one is a LinearLayout, initially invisible (actually "gone"), that I make visible in turn. I am having a very tough time getting one of these to display correctly on both tablets and phones, in both portrait and landscape. I can tune it to work on the phone, but then it doesn't display well on tablet-portrait.
The images here are set up to work well on 10" tablets in portrait, and they work for 7" tablets and phones in portrait, but not in landscape. In the images below, I would like the arrows (two ImageViews) to resize as needed to make room for the text. However, the Layout seems to give priority to the ImageViews no matter what I do.
(Note that I do realize I could make this work, in a way, with a RelativeLayout, however, I cannot get the translucent backgrounds to work, filling the screen, using a RelativeLayout, as far as I know.)
My question in brief: Is there a way to make LinearLayout prioritize the TextViews, giving them enough space, and resizing the ImageViews to fit the rest?
Here is a good layout (10" tablet, portrait, shown at reduced scale):
Here is a bad one with some of the text cut off (10" tablet, landscape, reduced scale):
Here is another bad one (phone):
I don't have a screenshot of the other tuning, but it displayed big arrows and no central "Tap to Continue" button.
Here is my current XML:
<RelativeLayout
android:id="#+id/main_holder"
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">
<LinearLayout
android:id="#+id/intro3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone"
android:onClick="introClicked"
android:clickable="true">
<LinearLayout
android:id="#+id/intro3_top"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="top|center_horizontal"
android:orientation="vertical"
android:gravity="top|center_horizontal">
<TextView
android:id="#+id/textViewIntro3_1"
fontPath="fonts/AsCuteAs...Heavy.ttf"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Swipe up to mark a spark completed."
android:layout_gravity="center_horizontal|top"
android:gravity="center"
android:layout_weight="1"
android:paddingBottom="5dp"
android:background="#C5000000"
android:textColor="#fff6c3"
android:textSize="30sp"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|bottom"
android:adjustViewBounds="false"
android:background="#drawable/grad_bottom"
android:padding="10dp"
android:layout_weight="1"
android:scaleType="fitCenter"
android:src="#drawable/arrow_up"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="vertical"
android:layout_weight="0"
android:background="#85000000"
android:gravity="center">
<TextView
android:id="#+id/button_intro3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:alpha="0"
android:background="#drawable/roundrect"
android:onClick="introClicked"
android:padding="10dp"
android:text="Tap to Continue"
android:clickable="true"
android:enabled="true"
android:textColor="#FFFFF6C3"
android:textSize="24sp"/>
</LinearLayout>
<LinearLayout
android:id="#+id/intro3_bottom"
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="1"
android:layout_gravity="bottom|center_horizontal"
android:gravity="bottom|center_horizontal">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|bottom"
android:adjustViewBounds="false"
android:background="#drawable/grad_top"
android:layout_weight="1"
android:padding="10dp"
android:scaleType="fitCenter"
android:src="#drawable/arrow_down"/>
<TextView
android:id="#+id/textViewIntro3_2"
fontPath="fonts/AsCuteAs...Heavy.ttf"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Swipe down to reject.\n "
android:layout_gravity="center_horizontal|bottom"
android:gravity="center"
android:layout_weight="1"
android:paddingBottom="0dp"
android:background="#C5000000"
android:textColor="#fff6c3"
android:textSize="30sp"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
There're several possible way of doing it. I've updated your layout a bit, so now it should meet your expectations:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="#+id/main_holder"
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">
<RelativeLayout
android:id="#+id/intro3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
android:onClick="introClicked"
android:clickable="true">
<TextView
android:id="#+id/textViewIntro3_1"
fontPath="fonts/AsCuteAs...Heavy.ttf"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Swipe up to mark a spark completed."
android:gravity="center"
android:layout_alignParentTop="true"
android:paddingBottom="5dp"
android:background="#C5000000"
android:textColor="#fff6c3"
android:textSize="30sp"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/button_intro3"
android:layout_below="#+id/textViewIntro3_1"
android:adjustViewBounds="false"
android:background="#drawable/grad_bottom"
android:padding="10dp"
android:scaleType="fitCenter"
android:src="#drawable/arrow_up"/>
<TextView
android:id="#+id/button_intro3"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:alpha="0"
android:background="#drawable/roundrect"
android:onClick="introClicked"
android:padding="10dp"
android:text="Tap to Continue"
android:clickable="true"
android:enabled="true"
android:textColor="#FFFFF6C3"
android:textSize="24sp"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="false"
android:background="#drawable/grad_top"
android:layout_below="#+id/button_intro3"
android:layout_above="#+id/textViewIntro3_2"
android:padding="10dp"
android:scaleType="fitCenter"
android:src="#drawable/arrow_down"/>
<TextView
android:id="#+id/textViewIntro3_2"
fontPath="fonts/AsCuteAs...Heavy.ttf"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Swipe down to reject.\n "
android:gravity="center"
android:layout_alignParentBottom="true"
android:paddingBottom="0dp"
android:background="#C5000000"
android:textColor="#fff6c3"
android:textSize="30sp"/>
</RelativeLayout>
</RelativeLayout>
What I did here is to rewrite the layout with RelativeLayout instead of LinearLayouts. It suits better here, in my humble opinion.
I hope, it helps.

Can't align ImageViews to the left in ListView Row (RelativeLayout)

This is how I have my view at the moment.
As you can see, the icons are not all aligned all the way to the left. The red line is my objective. If they go all the way to the left, no problem, because I can solve it later with marginLeft.
This is my XML code (layout/listview_style_listview.xml):
<?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:background="#color/BackGroundColor"
android:orientation="vertical"
android:scaleType="center" >
<LinearLayout
android:id="#+id/titleLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_marginLeft="7dp"
android:layout_marginRight="7dp"
android:background="#color/BackGroundColor"
android:orientation="horizontal" >
<TextView
android:id="#+id/sectionTitle"
style="#style/sectionTitle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="left"
android:text="(blank)" />
<Button
android:id="#+id/sectionInfoButton"
android:layout_width="33dp"
android:layout_height="33dp"
android:layout_gravity="right"
android:layout_marginLeft="3dp"
android:layout_weight="0"
android:background="#drawable/infoicon" />
<Button
android:id="#+id/sectionInfoButton"
android:layout_width="33dp"
android:layout_height="33dp"
android:layout_gravity="right"
android:layout_marginLeft="3dp"
android:layout_weight="0"
android:background="#drawable/filtericon" />
<Button
android:id="#+id/sectionOptionsButton"
android:layout_width="33dp"
android:layout_height="33dp"
android:layout_gravity="right"
android:layout_marginLeft="3dp"
android:layout_weight="0"
android:background="#drawable/menuicontop2" />
<Button
android:id="#+id/addCatButton"
android:layout_width="33dp"
android:layout_height="33dp"
android:layout_gravity="right"
android:layout_marginLeft="3dp"
android:layout_weight="0"
android:background="#drawable/effect_button_add_cat_click" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_marginBottom="0dp"
android:layout_marginLeft="0dip"
android:layout_marginRight="0dip"
android:background="#color/blueOceanStroke" />
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#color/BlueOcean"
android:dividerHeight="1dp"
android:listSelector="#drawable/listview_style_list_selector"
android:paddingBottom="1dp" />
</LinearLayout>
This is my XML code (layout/listview_style_row.xml)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minHeight="35dp" >
<ImageView
android:id="#+id/catThumbnail"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="#drawable/bank1" />
<TextView
android:id="#+id/sectionTitle"
style="#style/title"
android:layout_width="97dp"
android:layout_height="32dp"
android:layout_alignBottom="#+id/catThumbnail"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_marginLeft="66dp"
android:gravity="center_vertical"
android:text="Title Text"
android:textColor="#color/listsTextColor"
android:textSize="15sp"
android:textStyle="normal"
android:typeface="normal" />
<ImageView
android:layout_width="25dip"
android:layout_height="32dp"
android:layout_alignBottom="#+id/sectionTitle"
android:layout_alignParentRight="true"
android:gravity="center_vertical"
android:src="#drawable/arrow" />
</RelativeLayout>
PS: I added an arrow icon to the right after the screenshot and that's why it's not showing on the image but I guess it's not important.
From the screenshot the layout is OK because the divider with back color #color/blueOceanStroke goes all the way and so do the separators. The problem must be in the "#+id/catThumbnail", if you measure the distance between your red line and the left edge of the yellow square and compare it with the distance between the right edge of the square and the left edge of letter "B" they are about the same which it shouldn't be.
My guess is that there is some king of padding in the #drawable/bank1. Try to remove it completely and see if the letter "B" left aligns with the title.
Hope this helps...
I was able to fix it with android:layout_marginLeft="-10dp" on the "ImageView #+id/catThumbnail" in listview_style_row.xml, but i really dont think this is a valid solution for a final perfectly designed app, yes? For me to put negative values in there, theres something wrong, right?
As someone else mentioned, I would try removing the ImageView and seeing if the TextView will be flush against the red line. If it is, the ImageView has some issues, if not it's something else. Also, the ImageView may not have the same height and width and that could cause issues with the scaling you're doing by setting to 32 dp, see: Unwanted padding around an ImageView.
It might be easier to wrap your ImageView in a FrameLayout. Something like this:
<FrameLayout>
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
<ImageView
android:id="#+id/catThumbnail"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/bank1" />
</FrameLayout>
Or if that doesn't work, try setting the width and height of the image view and/or the frame layout to wrap_content. Also if that image is a 9-patch, there may be other causes.

Android trying to center 2 Images, but they get right justfied

I have a layout with a image of the card on the left hand side. The right hand side has 2 buttons on top. Then 2 images below them, and one image below the 2 images.
I would like the 2 images and 1 image to get centered.
The row with 1 image gets centred all right.
PARTIAL CODE
<LinearLayout
android:id="#+id/mainLayout"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="horizontal">
<ImageView
android:id="#+id/viewfacebook"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="#drawable/facebook" />
<ImageView
android:id="#+id/viewmail"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="#drawable/mail" />
</LinearLayout>
I create a horizontal container for the 2 images and set it's gravity to center. This is not working. I also tried to set the gravty to center on the 2 images. But.... they always stay to the left hand side.
THE WHOLE XML CODE
<?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">
<LinearLayout
android:id="#+id/mainLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical"></LinearLayout>
<LinearLayout
android:id="#+id/mainLayout"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:background="#drawable/background"
android:orientation="vertical">
<LinearLayout
android:id="#+id/mainLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/mainLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/cardpic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:src="#drawable/bio" />
</LinearLayout>
<LinearLayout
android:id="#+id/mainLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="#+id/mainLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal">
<ImageView
android:id="#+id/buthome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ok" />
<ImageView
android:id="#+id/butaffirmation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/affirmation" />
</LinearLayout>
<LinearLayout
android:id="#+id/mainLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal" />
<ImageView
android:id="#+id/viewfacebook"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#drawable/facebook" />
<ImageView
android:id="#+id/viewmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#drawable/mail" />
</LinearLayout>
<ImageView
android:id="#+id/vietwitter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#drawable/twitter" />
<LinearLayout
android:id="#+id/mainLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/housetext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" *A long and happy marriage or commitment is in your future.\n*Emotional security (loyalty and trust) exists in your relationship.\n*You will have a stable home and family life.\nThe marriage card is about a person who is either going get married or who really cherishes the whole institution of marriage."
android:textColor="#ff000000"
android:textSize="18px"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/cardtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" *A long and happy marriage or commitment is in your future.\n*Emotional security (loyalty and trust) exists in your relationship.\n*You will have a stable home and family life.\nThe marriage card is about a person who is either going get married or who really cherishes the whole institution of marriage."
android:textColor="#ff000000"
android:textSize="20dp"
android:textStyle="bold" />
</ScrollView>
</LinearLayout>
It's a little hard to follow your XML, but this should get you on the right track, give this a try.
If you are using linear layouts...
Nest the images you want to center side by side in a horizontal linear layout
Assign a layout weight to each image
You might have to play around with the layout_widths and heights using match_parent (or fill depending on your target API), and also with the layout_gravity and gravity params.
<LinearLayout android:gravity="center" ... orientation="horizontal">
<ImageView
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/viewmail"
android:src="#drawable/mail" />
<ImageView
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/vietwitter"
android:src="#drawable/twitter" />
</LinearLayout>
Edited the code within the question. I had a rough time trying to see what you were trying to do. A picture for the question might have been very straight forward (imo). Now to answer your question, understand that LinearLayouts have by default left-justification. If you have multiple LinearLayouts nested, take extra caution when deciding their widths and heights, as they take precedence over gravity.

Categories

Resources