I have looked up similar problems but their solutions aren't working. My Relative Layout is adding Left padding.
This is my XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:fillViewport="true"
android:padding="0dp" >
<ImageView
android:id="#+id/imageViewUserProfile"
android:layout_width="114dp"
android:layout_height="98dp"
android:layout_alignParentTop="false"
android:layout_margin="0dp"
android:adjustViewBounds="true"
android:padding="0dp"
android:src="#drawable/default_t" />
<TextView
android:id="#+id/textViewUserProfileName"
android:layout_width="fill_parent"
android:layout_height="44dp"
android:layout_alignParentTop="true"
android:layout_centerVertical="true"
android:layout_toRightOf="#id/imageViewUserProfile"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textViewUserProfileHighlights"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:layout_toRightOf="#id/imageViewUserProfile"
android:layout_below="#id/textViewUserProfileName"/>
</RelativeLayout>
</LinearLayout>
I removed the parenting LinearLayout to double check that the left padding was coming from atleast the RelativeLayout block. I have tried most of what worked for other people. Any help or suggestions would be greatly appreciated.
For the ImageView set alignParentTop and alignParentLeft to true also remove the LinearLayout, it is unnecessary.
Related
I have a problem to fill the whole screen with a scrollview.
How do I make the scrollview cover the whole screen width and screenheight? I tried with fillviewport but that that works for the screenheight.
I am not sure if its the scrollview or its parent (FrameLayout) that is the problem?
<?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" >
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fillViewport="true">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/img1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="img1"/>
<TextView
android:id="#+id/text_img1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
/>
<ImageView
android:id="#+id/img2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="img2"/>
<TextView
android:id="#+id/text_img2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
/>
<ImageView
android:id="#+id/img3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="img3"/>
<TextView
android:id="#+id/text_img3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
/>
</LinearLayout>
</ScrollView>
change your ScrollView and LinearLayout like this
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
Change your <ScrollView> from wrap_content to match_parent.
Example:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center">
Also, you should be using match_parent instead of fill_parent in API 8+.
EDIT:
After talking a bit in the comments, OP and I discovered that the FrameLayout's default background is transparent, which means you can see the old view underneath.
Using a LinearLayout or really anything instead of a FrameLayout will fix this problem.
Other answers are going in the right direction but your main problem is probably due to the fact that it's a Dialog.
First of all make sure your Dialog is borderless. You can use one of approaches proposed here (not to duplicate answers).
I was wondering if anyone could explain a small problem i'm having. I'm trying to get my head around RelativeLayouts and have the following:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="vertical"
android:background="#ffffff"
android:layout_height="fill_parent" >
<ImageView
android:id="#+id/newsImage"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_alignParentLeft="true"
android:background="#ffffff" >
</ImageView>
<TextView
android:id="#+id/newsSubtitle"
android:layout_height="fill_parent"
android:layout_width="200dp"
android:textColor="#0098bf"
android:layout_centerVertical="true"
android:layout_alignRight="#+id/newsImage"
android:textSize="18sp">
</TextView>
<TextView
android:id="#+id/newsId"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:visibility="invisible"
android:textSize="0sp" >
</TextView>
</RelativeLayout>
As i understand it in RelativeLayouts you can align children to the parent (RelativeLayout) using 'alignParentLeft="true"', and you can align each child to other children using alignRight="#+id/childId". This seems to work well enough with TextViews, however i'm having trouble getting my ImageViews to behave properly - it's like they don't actually seem to take up any space, as the TextView just sits on top of the image instead of aligning to the right of the image.
Am i misunderstanding something here or do RelativeLayouts have a different way of aligning Image / Text combinations?
Call android:layout_below="#id/idofImageView" on your textview and add an image to the ImageView.
Edit: Sorry you want it to the right: android:align_toRightOf="#id/ImagevIEW"
Use this code.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="vertical"
android:background="#ffffff"
android:layout_height="fill_parent" >
<ImageView
android:id="#+id/newsImage"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_alignParentLeft="true"
android:background="#ffffff" >
</ImageView>
<TextView
android:id="#+id/newsId"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:visibility="gone"
android:textSize="0sp" >
</TextView>
<TextView
android:id="#+id/newsSubtitle"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:textColor="#0098bf"
android:textSize="18sp" />
</RelativeLayout>
I have a relative layout, and inside it i place 3 items, 2 imageviews and one scrollview.
My layout is like this...
<?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:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal"
android:baselineAligned="true"
android:background="#drawable/background">
<RelativeLayout
android:id="#+id/logosLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="1"
android:layout_margin="16dp"
android:gravity="center">
<!-- An image will be placed here -->
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_weight="1"
android:background="#33ffffff"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="#drawable/up" />
<ScrollView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_margin="8dp"
android:fadingEdgeLength="32dp"
android:scrollbars="none" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
<ImageButton
android:id="#+id/hotelBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:background="#drawable/button_background"
android:contentDescription="#string/hotelBtnDesc"
android:gravity="center"
android:src="#drawable/icon1" />
<TextView
android:id="#+id/hotelBtnDescTxtVw"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:gravity="center"
android:text="#string/hotelBtnDesc"
android:textColor="#ffffff"
android:textSize="14sp" />
<!-- more scrollview items -->
</LinearLayout>
</ScrollView>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:src="#drawable/down" />
</RelativeLayout>
</LinearLayout>
The above code produces the view shown here:
You may note that the arrows are not aligned in the center, but are slightly moved to the right. Why is that, and how can I fix it ? Note that i have already used android:layout_centerHorizontal="true" to my imageviews.
Thank you in advance
Its problem with your
android:layout_margin="8dp"
remove it from both scrollview and imageView
and pass it to RelativeLayout direct.
or add
android:layout_marginTop="8dip"
android:layout_marginBottom="8dip"
in your RelativeLayout.
and pass
android:layout_centerHorizontal="true"
to your scrollview
they are aligned to the center if you put the marginRight into consideration, try adding android:layout_margin="8dp" to the arrows.
u need to set image view that is under the Relative layout set this image view width fill parent.
Try removing android:layout_weight="1" from your RelativeLayout and see if it works.
In your LinearLayout, the attribute android:orientation="horizontal" causing your display to be aligned horizontaly. Therefore your RelativeLayout is in center but since its shared with another layout thats why you cant note the difference. If you completely remove the first RelativeLayout (the one with id logosLayout) then i hope you'll see the second layout in center.
So, first you need to define the hierarchy of layout you require and then adjust your views accordingly.
It seems problem with your android:layout_margin="8dp" for your scrollview only and pass it to RelativeLayout direct but instead of using margin use padding = "8dp".
I have some behaviour of my layout. I give two of them, very similar to each other. Only one difference is the width attribute of the textviews.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:isScrollContainer="true"
android:gravity="center"
android:background="#color/black">
<LinearLayout
android:id="#+id/tabs"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:background="#color/black"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Einstellungen"
android:drawableTop="#drawable/selector_settings"
android:id="#+id/main_menu_button_connection"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="10px">
</TextView>
...
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Suche"
android:drawableTop="#drawable/selector_search"
android:id="#+id/main_menu_button_connection"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="10px">
</TextView>
</LinearLayout>
</LinearLayout>
</LinearLayout>
If layout_width is set to wrap content, I get following layout results:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:isScrollContainer="true"
android:gravity="center"
android:background="#color/black">
<LinearLayout
android:id="#+id/tabs"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:background="#color/black"
android:layout_weight="1">
<TextView
android:layout_width="70dp"
android:layout_height="wrap_content"
android:text="Einstellungen"
android:drawableTop="#drawable/selector_settings"
android:id="#+id/main_menu_button_connection"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="10px">
</TextView>
...
<TextView
android:layout_width="70dp"
android:layout_height="wrap_content"
android:text="Suche"
android:drawableTop="#drawable/selector_search"
android:id="#+id/main_menu_button_connection"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="10px">
</TextView>
</LinearLayout>
</LinearLayout>
</LinearLayout>
If layout_width is set to a value instead (here 70dp), my layout looks so, I want it to have:
Can anybody explain me, why?!
Is there some solution avoiding to set a constant width and still having layout result like at the second picture?!
Thank you in advance
You probably want to give each TextView an equal layout weight such as android:layout_weight="1" and a width of fill_parent. Also, don't give a weight for the tabs linear layout. Also, while I don't really know what's going on later in the layout file, having three nested LinearLayouts seems like it might be wasteful. Maybe you can get rid of one of them?
I recommend starting over and using the eclipse designer view or use droiddraw to create the layout, especially since there are recent improvements to the layout editor.
I'm just beginning Android and have gotten myself stuck. I've made a simple app/view. The idea is draw a line-maze in the top, with motion buttons on the bottom. My app only draws an x with a couple lines in the frame, but that works. The problem is that my buttons are being drawn too far down, and are clipped in height.
I assume the problem is all in my layout xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<none.maze.MazeView
android:id="#+id/maze"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/text"
android:text="#string/maze_layout_text_text"
android:visibility="visible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center_horizontal"
android:textColor="#ff8888ff"
android:textSize="24sp"/>
</RelativeLayout>
</FrameLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<Button
android:id="#+id/left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Left"
android:layout_weight="1"
/>
<Button
android:id="#+id/forward"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Forward"
android:layout_weight="1"
/>
<Button
android:id="#+id/right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Right"
android:layout_weight="1"
/>
</LinearLayout>
</LinearLayout>
I think you shouldn't use layout_height="fill_parent" and layout_weight at the same time. Try to set layout_height="0dip" and layout_weight="1" for the FrameLayout and layout_height="wrap_content" for the lower LinearLayout. The lower LinearLayout mustn't have the layout_weight attribute.
Use Hierarchy Viewer to debug your layout. Its pretty cool.
Your entire layout is just way too bloated and ineffective. You use way too many ViewGroups. I recommend reading about RelativeLayouts and especially the entire Layout Tricks series.