How to show three labels and spinner just below my textbox? - java

I am working with android and I have designed my xml in which I am showing three buttons at the bottom of my screen and also I am showing a textbox (textboxA) at the center of my screen along with three buttons at the bottom of the screen.
Now I would like to show three labels and three spinners just below the textboxA Is possible to do? I tried using the below code but some of my labels and spinners are off
textboxA
labelA: SpinnerA
labelB: SpinnerB
labelC: SpinnerC
Below is my xml layout -
<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"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:orientation="horizontal" >
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="ButtonA" />
<Button
android:id="#+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="ButtonB" />
<Button
android:id="#+id/button3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="ButtonC" />
</LinearLayout>
<EditText
android:id="#+id/edittext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:ems="10"
android:hint="textboxA"
android:inputType="text" >
</EditText>
<TextView
android:id="#+id/text_view_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Radius1: " />
<Spinner
android:id="#+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/edittext"
android:layout_centerHorizontal="true" />
<TextView
android:id="#+id/text_view_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Radius2: " />
<Spinner
android:id="#+id/spinner2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/edittext"
android:layout_centerHorizontal="true" />
<TextView
android:id="#+id/text_view_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Radius3: " />
<Spinner
android:id="#+id/spinner3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/edittext"
android:layout_centerHorizontal="true" />
Is there anything wrong I am doing here?

If you are using RelativeLayout you should use toLeftOf or above or below xml properties in the items to define their positions
Edit:
Try this layout, obviously you will have to tweek it a bit to fullfil your needs:
<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"
android:orientation="vertical" >
<EditText
android:id="#+id/edittext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:ems="10"
android:hint="textboxA"
android:inputType="text" >
</EditText>
<LinearLayout
android:id="#+id/firstRadius"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/edittext" >
<TextView
android:id="#+id/text_view_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radius1: " />
<Spinner
android:id="#+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="#+id/secondRadius"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/firstRadius" >
<TextView
android:id="#+id/text_view_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radius2: " />
<Spinner
android:id="#+id/spinner2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="#+id/thirdRadius"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/secondRadius" >
<TextView
android:id="#+id/text_view_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radius3: " />
<Spinner
android:id="#+id/spinner3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:orientation="horizontal" >
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="ButtonA" />
<Button
android:id="#+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="ButtonB" />
<Button
android:id="#+id/button3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="ButtonC" />
</LinearLayout>
</RelativeLayout>
Hope it is helpful.

Related

Scale imageview on tablet with original aspect

I have the code below and I face a problem with the image view "#+id/logo_skilfull" because it does not keep the aspect.. I think is because of the scaleType or the adjustViewBounds..
image in tablet
image in a phone (I want this)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayoutMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFF"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:keepScreenOn="true" >
<View
android:id="#+id/view"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_alignParentTop="true" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/view2"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/view"
android:layout_centerHorizontal="true"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:background="#drawable/registration_background"
android:orientation="vertical"
android:padding="25dp" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/member_login_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:text="Ingresá tu DNI"
android:textSize="25dp"
android:textStyle="bold"
android:typeface="monospace" />
<EditText
android:id="#+id/username_edtext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/member_login_tv"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp"
android:background="#drawable/register_uname"
android:gravity="center"
android:hint="Documento"
android:imeOptions="actionDone"
android:inputType="number"
android:singleLine="true"
android:textColor="#000000"
android:textSize="30dp"
android:textStyle="bold" />
<Button
android:id="#+id/login_button"
style="#style/button_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/username_edtext"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp"
android:background="#drawable/button_access"
android:text="Aceptar"
android:textColor="#ffffff" />
<ImageView
android:id="#+id/logo_skilfull"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:background="#drawable/logos"
android:scaleType="matrix"
android:layout_alignParentBottom="true" />
</RelativeLayout>
</LinearLayout>
<View
android:id="#+id/view2"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true" />
<ImageView
android:id="#+id/view_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:background="#drawable/member_imview" />
</RelativeLayout>
You should read about the ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
This is a problem changing the size of the View. You need to set scaleType.
Try fitStart.
<ImageView
android:id="#+id/logo_skilfull"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:background="#drawable/logos"
android:scaleType="fitStart"
android:layout_alignParentBottom="true" />

Push keyboard to layout

I have an edittext, and when I focus on that, the footer layout was pushed together. How to hide footer when focus on edittext.
Before focus
After focus
this is my source code
<ListView
android:id="#+id/list_chat_rom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/rl_footer_send"
android:divider="#android:color/transparent"
android:dividerHeight="5dp"></ListView>
<RelativeLayout
android:id="#+id/rl_footer_send"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/menu_bar_bg">
<RelativeLayout
android:id="#+id/rl_insert_chat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingTop="10dp">
<ImageView
android:id="#+id/btn_send_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#drawable/layout_imv_send_message" />
<EditText
android:id="#+id/edit_insert_chat"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_toLeftOf="#id/btn_send_msg"
android:background="#drawable/layout_edit_text_chat"
android:hint="type to filter"
android:inputType="text"
android:maxLines="1"
android:textColor="#color/black" />
</RelativeLayout>
<View
android:id="#+id/view_line"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_below="#id/rl_insert_chat"
android:background="#color/black"></View>
<RelativeLayout
android:id="#+id/rl_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/view_line"
android:paddingBottom="5dp"
android:paddingLeft="20dp"
android:paddingRight="10dp"
android:paddingTop="5dp">
<ImageView
android:id="#+id/imv_avatar_chat"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerVertical="true"
android:adjustViewBounds="true"
android:scaleType="centerCrop" />
<RelativeLayout
android:id="#+id/rl_content_home"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/imv_avatar_chat">
<TextView
android:id="#+id/tv_name_user"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="user name"
android:textColor="#color/white" />
<TextView
android:id="#+id/tv_level"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/tv_name_user"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="lv : 10"
android:textColor="#color/white" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:layout_marginRight="10dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:src="#drawable/target_icon" />
<TextView
android:id="#+id/tv_point_show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10/125" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="10dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:src="#drawable/gem_icon" />
<TextView
android:id="#+id/tv_xu_show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="100" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<TextView
android:id="#+id/tv_login_facebook"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
android:layout_toRightOf="#id/imv_avatar_home"
android:text="ĐĂNG NHẬP BẰNG FACEBOOK"
android:visibility="gone" />
</RelativeLayout>
</RelativeLayout>
Why don't you try to hide it?
You can try to detect the keyboard state with this :
final View activityRootView = findViewById(R.id.activityRoot);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
... do something here
}
}
});
Note : Taken from here
And then you just hide the view that you want to hide.
Try with
android:windowSoftInputMode="adjustPan"
in the Activity declaration in the manifest

LinearLayout on android

I was trying to create a sign up form for my Android application
This is my XML code
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<TextView
android:id="#+id/mynumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Number +961"
android:textSize="20sp"
android:color="#android:color/white" />
<EditText
android:id="#+id/editTextNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Number"
android:textColor="#FFFFFF" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="vertical" >
<Button
android:id="#+id/buttonCreateAccount"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="60dp"
android:background="#drawable/ic_create" />
</LinearLayout>
</LinearLayout>
If you notice the first LinearLayout has a horizontal orientation and gravity (I want both the textview and edit text to be next to each others)
After the first linear layout i want the create account button to come out
However it is showing up on the same line with the previous edit text and text view
Any idea if i should change in the settings of the second linear layout
Change it like this
<LinearLayout
android:gravity="center_horizontal"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<LinearLayout
android:gravity="center_vertical"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="horizontal">
<TextView
android:color="#android:color/white"
android:id="#+id/mynumber"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Number +961"
android:textSize="20sp" />
<EditText
android:hint="Number"
android:id="#+id/editTextNumber"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#FFFFFF" />
</LinearLayout>
<Button
android:background="#drawable/ic_create"
android:id="#+id/buttonCreateAccount"
android:layout_height="wrap_content"
android:layout_marginBottom="60dp"
android:layout_width="fill_parent" />
</LinearLayout>
Try Below Xml File
Use Relative layout Or One MAin LinearLayout with Vertical Orientation and in sub take Horizontal as you required.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<TextView
android:id="#+id/mynumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Number +961"
android:textSize="20sp"
android:color="#android:color/white" />
<EditText
android:id="#+id/editTextNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Number"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal" >
<Button
android:id="#+id/buttonCreateAccount"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="60dp"
android:background="#drawable/ic_create" />
</LinearLayout>
</LinearLayout>
<?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="match_parent"
android:orientation="vertical"
android:background="#drawable/sign">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="1200dp">
<TableLayout
android:layout_marginTop="40dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Signup for Juju's"
android:textSize="35dp"
android:textColor="#f45"
android:textStyle="bold" />
<TableRow
android:weightSum="20"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_weight="5"
android:id="#+id/nametv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First Name"
android:textSize="25dp"
android:textColor="#23f" />
<EditText
android:textSize="16dp"
android:layout_marginRight="5dp"
android:layout_weight="15"
android:id="#+id/name"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:hint="Enter your name" >
</EditText>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:weightSum="20"
android:layout_height="wrap_content" >
<TextView
android:layout_weight="5"
android:textColor="#23f"
android:id="#+id/emailtv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email"
android:textSize="25dp" />
<EditText
android:textSize="16dp"
android:layout_weight="15"
android:layout_marginRight="5dp"
android:id="#+id/email"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:hint="Enter E-mail" />
</TableRow>
<TableRow
android:weightSum="20"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_weight="5"
android:textColor="#23f"
android:id="#+id/phonetv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Phone"
android:textSize="25dp" />
<EditText
android:textSize="16dp"
android:layout_marginRight="5dp"
android:layout_weight="15"
android:id="#+id/phone"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:hint="Enter Phone Number" />
</TableRow>
<TableRow
android:weightSum="20"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_weight="5"
android:textColor="#23f"
android:id="#+id/addresstv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Address"
android:textSize="25dp" />
<EditText
android:textSize="16dp"
android:layout_marginRight="5dp"
android:layout_weight="15"
android:id="#+id/address"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:hint="Enter Address" />
</TableRow>
<TableRow
android:weightSum="20"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_weight="5"
android:textColor="#23f"
android:id="#+id/usernametv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Username"
android:textSize="25dp" />
<EditText
android:textSize="16dp"
android:layout_weight="15"
android:layout_marginRight="5dp"
android:id="#+id/username"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:hint="Username" />
</TableRow>
<TableRow
android:weightSum="20"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_weight="5"
android:textColor="#23f"
android:id="#+id/passwordtv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password"
android:textSize="25dp" />
<EditText
android:textSize="16dp"
android:layout_marginRight="5dp"
android:layout_weight="15"
android:id="#+id/password"
android:inputType="textPassword"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:hint="Password" />
</TableRow>
<TableRow
android:weightSum="20"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_weight="5"
android:textColor="#23f"
android:id="#+id/confirmtv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reenter"
android:textSize="25dp" />
<EditText
android:textSize="16dp"
android:layout_marginRight="5dp"
android:layout_weight="15"
android:inputType="textPassword"
android:id="#+id/confirm"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:hint="Confirm Password" />
</TableRow>
<CheckBox
android:id="#+id/view_password"
android:checked="false"
android:textSize="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="View Password"
android:textColor="#000"/>
<ImageView
android:clickable="true"
android:id="#+id/submit"
android:layout_gravity="center"
android:layout_width="122dp"
android:layout_height="74dp"
android:src="#drawable/button" />
</TableLayout>
</ScrollView>
</LinearLayout>
Change your layout type;
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical" >
Definitely. What your are doing is encapsulating the second LinearLayout inside the first LinearLayout, that dictates a horizontal layout, ultimately resulting in horizontal positioning of all three components. Your hierarchy is as follows:
LinearLayout-Horizontal[TextView + EditText + LinearLayout-Vertical[Button]]
When supplying a LinearLayout with an orientation parameter, you're telling it to arrange all its children in that manner.
What I would recommend to you, to achieve the desired look is either:
Use a RelativeLayout (http://developer.android.com/guide/topics/ui/layout/relative.html) and position the elements in relation to each other and their parent.
Nest several LinearLayouts(not a recommended practice; here it wouldn't prove an issue but in larger and more complex layouts nesting too many such components may ultimately result in long rendering time for your view). This solution is pretty similar to what you have now and would work as follows:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal" >
<TextView
android:id="#+id/mynumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Number +961"
android:textSize="20sp"
android:color="#android:color/white" />
<EditText
android:id="#+id/editTextNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Number"
android:textColor="#FFFFFF" />
</LinearLayout>
<Button
android:id="#+id/buttonCreateAccount"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="60dp"
android:background="#drawable/ic_create" />
</LinearLayout>
Here you tell your outer layout to position its children vertically, where one of its children is a LinearLayout that positions its children horizontally, resulting in:
[[TEXT][EDIT]]
[ BUTTON ]
Hope this helps.

XML code for textview to view in the end of page of a scroll View

In my Android app.. I need my textview..( textview about contact us) so this textview has to be at the end of the page of the scroll view.. it should be above the scrollview.. I did code like this but what happening is textview is filling from the centre to the bottom..
I am giving my code below.. I used align_parentbottom ... but the text is at the centre and the rest portion is filling till the bottom with the background color..
xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/orange"
android:fillViewport="true"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/rLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content">"
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="18dp"
android:padding="15dip"
android:text="Current Challenge"
android:textSize="18dip" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView3"
android:layout_alignBottom="#+id/textView3"
android:layout_toRightOf="#+id/textView3"
android:text="PDNo" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView1"
android:layout_marginTop="20dp"
android:padding="15dip"
android:text="Your Current Challenge : "
android:textSize="16dip" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView3"
android:layout_marginLeft="14dp"
android:layout_marginTop="29dp"
android:text="Prediction for your Current Challenge will be displayed here..." />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView4"
android:layout_alignParentBottom="true"
android:background="#drawable/title_border"
android:padding="15dip"
android:text="Contact us :"
android:textColor="#FFFFFF"
/>
</RelativeLayout>
</ScrollView>
<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"
android:background="#color/orange">
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/textView5"
android:fillViewport="true"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/rLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="18dp"
android:padding="15dip"
android:text="Current Challenge"
android:textSize="18dip" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView3"
android:layout_alignBottom="#+id/textView3"
android:layout_toRightOf="#+id/textView3"
android:text="PDNo" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView1"
android:layout_marginTop="20dp"
android:padding="15dip"
android:text="Your Current Challenge : "
android:textSize="16dip" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView3"
android:layout_marginLeft="14dp"
android:layout_marginTop="29dp"
android:text="Prediction for your Current Challenge will be displayed here..." />
</RelativeLayout>
</ScrollView>
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="#000000"
android:padding="15dip"
android:text="Contact us :"
android:textColor="#FFFFFF" />
</RelativeLayout>
remove android:layout_below="#+id/textView4" from textView5

Scaling issue in a RadioButton with text

Please have a look at the following code
input.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=".MainActivity"
android:background="#drawable/background_main" >
<ImageView
android:id="#+id/logo_image"
android:background="#drawable/background_green"
android:src="#drawable/titleimage"
android:layout_width="match_parent"
android:layout_height="50dp"
/>
<ScrollView
android:id="#+id/scroller"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/logo_image"
android:layout_marginTop="10dp"
>
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:stretchColumns="*" >
<TableRow
android:id="#+id/device_type_row"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:layout_marginRight="5dp" >
<RadioButton
android:id="#+id/device_type_radio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_weight="2"
android:text="#string/device_type" />
<RadioGroup
android:id="#+id/device_type_radio_selection"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal">
<RadioButton
android:id="#+id/radioIos"
android:layout_width="wrap_content"
android:layout_height = "wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/iOS"
/>
<RadioButton
android:id="#+id/radioAndroid"
android:layout_width="wrap_content"
android:layout_height = "wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/android"
/>
</RadioGroup>
</TableRow>
<TableRow
android:id="#+id/days_as_customers_row"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:layout_marginRight="5dp" >
<RadioButton
android:id="#+id/days_as_customers_radio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/days_as_customers" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:weightSum="2" >
<SeekBar
android:id="#+id/days_as_customer_seekbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:id="#+id/days_as_customer_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1/210"
android:layout_weight="1"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</TableRow>
</TableLayout>
</ScrollView>
<Button
android:id="#+id/input_submit_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#drawable/submit_button_img" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="#drawable/logo"/>
</RelativeLayout>
Basically, this gives the following UI
Now the problem is, the RadioButtons with text in the first column of the table takes only 40% of the available width. But, I need them to take 75% of the available width, and the things in second column can get the rest.
How can I do this?
Try this..
<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=".MainActivity"
android:background="#drawable/background_main" >
<ImageView
android:id="#+id/logo_image"
android:background="#drawable/background_green"
android:src="#drawable/titleimage"
android:layout_width="match_parent"
android:layout_height="50dp"
/>
<ScrollView
android:id="#+id/scroller"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/logo_image"
android:layout_marginTop="10dp"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout
android:id="#+id/device_type_row"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:layout_marginRight="5dp" >
<RadioButton
android:id="#+id/device_type_radio"
android:layout_width="0dp"
android:layout_weight="0.75"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/device_type" />
<RadioGroup
android:id="#+id/device_type_radio_selection"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:orientation="horizontal">
<RadioButton
android:id="#+id/radioIos"
android:layout_width="wrap_content"
android:layout_height = "wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/iOS"
/>
<RadioButton
android:id="#+id/radioAndroid"
android:layout_width="wrap_content"
android:layout_height = "wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/android"
/>
</RadioGroup>
</LinearLayout>
<LinearLayout
android:id="#+id/days_as_customers_row"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:layout_marginRight="5dp" >
<RadioButton
android:id="#+id/days_as_customers_radio"
android:layout_width="0dp"
android:layout_weight="0.75"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/days_as_customers" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.25">
<SeekBar
android:id="#+id/days_as_customer_seekbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:id="#+id/days_as_customer_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1/210"
android:layout_weight="1"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
<Button
android:id="#+id/input_submit_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#drawable/submit_button_img" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="#drawable/logo"/>
</RelativeLayout>

Categories