Here is a simple RelativeLayout with 4 controls arranged in a tabular format.
When displayed, the confirmpassword box is clipped at the bottom. It's as if "wrap_content" is not correctly calculating the height of the children. Any ideas?
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/passwordlabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="34dp"
android:text="Password"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#id/passwordlabel"
android:layout_alignLeft="#+id/confirmpassword"
android:layout_toRightOf="#id/passwordlabel"
android:ems="10"
android:inputType="textPassword" >
<requestFocus />
</EditText>
<TextView
android:id="#+id/confirmpasslabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/passwordlabel"
android:layout_below="#id/passwordlabel"
android:text="Confirm Password"
android:layout_marginTop="34dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/confirmpassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#id/confirmpasslabel"
android:layout_toRightOf="#id/confirmpasslabel"
android:layout_marginLeft="15dp"
android:ems="10"
android:inputType="textPassword" />
</RelativeLayout>
This is what it looks like:
I have tried adding padding and/or margins to both of the bottom controls which has no effect (and strikes me as a hack anyway).
NB:- I had a similar problem before which a kindly soul solved essentially by splitting apart the RelativeLayout. I don't think that's possible here (it may be) but I'm concerned I'm either doing something completely wrong, or the RelativeLayout has a massive bug which seems under-documented.
Anyone able to shed light on this? TIA!
It does seem like a bit of a bug. I couldn't get it to work properly (without changing it somehow) with a RelativeLayout - something with the margins was throwing it off.
As a workaround, try a TableLayout:
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TableRow android:layout_marginTop="34dp">
<TextView
android:id="#+id/passwordlabel"
android:text="Password"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/password"
android:ems="10"
android:inputType="textPassword" >
<requestFocus />
</EditText>
</TableRow>
<TableRow android:layout_marginTop="34dp">
<TextView
android:id="#+id/confirmpasslabel"
android:text="Confirm Password"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/confirmpassword"
android:layout_marginLeft="15dp"
android:ems="10"
android:inputType="textPassword" />
</TableRow>
</TableLayout>
Related
I need help.
At work, I was given a task to figure out why ScrollView overlaps part of the text. The layout is multi-layered, and I think the problem lies in this. I'm new to android studio and it's still hard for me to understand the relationships of all objects.
all the XML is here https://docs.google.com/document/d/1PaGIWPn2w6ubZraVpQfq8Rrqo0uCWYOiIbxnCWaIKTQ/edit?usp=sharing
below is a part of the code
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center|left|center_vertical"
android:orientation="vertical">
<TextView
android:id="#+id/tvMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="2dp"
android:textColor="#color/mainBlackColor"
android:textSize="24dp"
tools:text="Сообщение" />
<TextView
android:id="#+id/tvDetails"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/red"
android:lines="3"
android:paddingStart="3dp"
android:paddingLeft="3dp"
android:paddingTop="2dp"
android:paddingEnd="3dp"
android:paddingRight="3dp"
android:paddingBottom="2dp"
android:textColor="#color/mainTextColor"
android:textSize="18dp"
android:visibility="gone"
app:autoSizeMaxTextSize="18dp"
app:autoSizeMinTextSize="10dp"
app:autoSizeStepGranularity="4dp"
app:autoSizeTextType="uniform"
tools:text="Детали"
tools:visibility="visible" />
</LinearLayout>
</ScrollView>
Add android:scrollbarStyle="outsideOverlay" and padding_horizontal to your scrollView. This should solve your issue.
So i am making an application for school. We have to use Android studio.
I want to make a bar with an icon and a placeholder (android: hint).
When i make this with this code, the hint text is at the left of the box.
<EditText
android:layout_width="280dp"
android:layout_height="55dp"
android:inputType="textEmailAddress"
android:ems="10"
android:id="#+id/email"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:background="#drawable/email"
android:hint="Email" <---
/>
When i do it like this, the hint text is centered:
<EditText
android:layout_width="280dp"
android:layout_height="55dp"
android:inputType="textEmailAddress"
android:ems="10"
android:id="#+id/email"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:background="#drawable/email"
android:hint="Email"
android:gravity="center" <---
/>
How can i change the place of my hint text in other ways? I want it to be in 1/3 of the box.
But i have no idea how to do it.
Thanks in advance
Just dont use the gravity and use padding left :).
<EditText
android:layout_width="280dp"
android:layout_height="55dp"
android:inputType="textEmailAddress"
android:ems="10"
android:id="#+id/email"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:background="#drawable/email"
android:hint="Email"
android:paddingLeft="70dp" />
How can I style/customize spinner like shown below using xml?
I can make white background with border, but i can't set icon on the left and arrow on the right.
If your problem is with a layout that sets the icon to the left and arrow to the right, the following should work.
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ImageView
android:id="#+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true" />
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/icon" />
<ImageView
android:id="#+id/arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true" />
</RelativeLayout>
I'm at work, so I can't test this out, but I think it should work.
Can someone please give me directions on this:
I've got a ListView, the adapter got a LinearLayout and in this I got four more LinearLayouts.
Now I read about dp and it is relative to 160, but when I read different examples this number "160" seems to be different on different screens, so how do I work with dp?
I am used to work with % in this cases.
Now I want my four LinearLayouts to be:
55dp
35pd
35pd
35pd
Like if the dp was 160!
But as I mentioned above, this dosen't work on all screens.
Can someone tell me how I should work with this? Directions or a good tutorial or similar?
This is what I have tried, and come up with so far:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="15dip"
android:layout_marginBottom="15dip"
android:paddingTop="15dip"
android:paddingBottom="15dip" >
<LinearLayout
android:orientation="vertical"
android:layout_width="55dp"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:id="#+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="35dp"
android:layout_height="wrap_content"
android:gravity="center">
<Button
android:text="Woho"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:text="Woho"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button
android:text="Woho"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="35dp"
android:layout_height="wrap_content"
android:gravity="center">
<Button
android:text="Woho"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:text="Woho"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button
android:text="Woho"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
As per the android documentation, 1 DP = 1 pixel on a 160 DPI screen. If the screen is 240 DPI, then 1.5pixel = 1 DP. the size of one DP is independent of underlying hardware resolution but a function of DPI of the screen.
To your layout question, if you assign a fixed width value to your layout, then it will not look good on larger screen sizes.
Better to use layoutweight to distribute the width between those layouts.
I'm sure it's very simple and I'm just being stupid, but I've tried numerous variants and still can't get it working. What's worse - these 3 components are aligned exactly the way I want in the graphical editor in Eclipse, but not on the real device. I only get to align it to 50% for TextView and RadioGroup.
The XML goes like this currently (here I presumed RadioGroup is kind of LinearLayout):
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
style="#style/ButtonStyle"
android:layout_width="wrap_content"
android:text="#string/CC_Direction_caption" />
<RadioButton
android:id="#+id/rb_toCamera"
style="#style/ButtonStyle"
android:text="#string/CC_Backwards_Caption" />
<RadioButton
android:id="#+id/rb_toInfinity"
style="#style/ButtonStyle"
android:text="#string/CC_Forwards_Caption" />
</RadioGroup>
And the ButtonStyle is:
<item name="android:layout_width">0dip</item>
<item name="android:layout_height">70dp</item>
<item name="android:layout_weight">1</item>
And all this is inside a TableRow.
Use android:layout_centerVertical="true" in your TextView.
Below is a sample:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical" >
<TextView
android:id="#+id/typeLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="GroupBox Label"
android:textColor="#color/black"
android:textSize="14dp" />
<RadioGroup
android:id="#+id/radioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/white"
android:layout_alignParentRight="true"
android:gravity="center"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Radio 1 Text"
android:textColor="#color/blue" />
<RadioButton
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio 2 t"
android:textColor="#color/blue" />
</RadioGroup>
</RelativeLayout>
Try adding android:layout_weight="1" to all three elements. This specifies the relative weight every element has to the others. The higher this value is the less weight the element gets.
oh, and wrap everything in a linear layout (didn't see you didn't add a layout first).
You should use a Linear Layout with weights on your elements which will make it pretty easy to achieve what you want.
Check the docs for info on Linear Layout and weights.
http://developer.android.com/guide/topics/ui/layout-objects.html
Try changing layout_width to "wrap_content" for radio buttons as well. You have already done it for the text field.