How can i align the "LoginBox" LinearLayout to its parent (that is a RelativeLayout) both at left/right and bottom? I tried to insert:
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
but it doesn't do the trick! Infact the linearlayout is not properly aligned to the margin of the screen! :(
This is my XML code:
<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="#drawable/sfondologin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/stemmatrasparente" />
<LinearLayout
android:id="#+id/LoginBox"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/usernametxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:background="#drawable/sfondobuttonedittext"
android:drawableLeft="#drawable/usericon"
android:ems="10"
android:gravity="center_horizontal|center"
android:paddingLeft="15dp"
android:imeOptions="actionNext"
android:singleLine="true"
android:textSize="18dp"
android:typeface="sans" >
<requestFocus />
</EditText>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.18" >
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<EditText
android:id="#+id/passwordtxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:background="#drawable/sfondobuttonedittext"
android:drawableLeft="#drawable/lockicon"
android:ems="10"
android:gravity="center_vertical|center"
android:inputType="textPassword"
android:paddingLeft="15dp"
android:imeOptions="actionDone"
android:textSize="18dp"
android:typeface="sans" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.29" >
<TextView
android:id="#+id/forgotpass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="Dimenticato la password?"
android:textColor="#color/white"
android:textColorHint="#color/white"
android:textSize="#dimen/value12dp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/loginbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#drawable/sfondobuttonlogin"
android:text="Login"
android:textColor="#color/white" />
</RelativeLayout>
<Button
android:id="#+id/registerbtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center|end"
android:background="#drawable/sfondobuttonrb2"
android:text="Registrati"
android:textColor="#color/white" />
</LinearLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="left"
android:layout_weight="0.01"
android:background="#00000000">
</RelativeLayout>
</RelativeLayout>
Thank you in advance!
EDIT:
The first screen is what i have now! While the second, edited with photoshop (sorry), is what i want to get!
Remove
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
these lines form your outermost ReletiveLayout.
Thats it!
Try this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom">
<Button
android:id="#+id/registerbtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center|end"
android:background="#drawable/sfondobuttonrb2"
android:text="Registrati"
android:textColor="#color/white" />
</LinearLayout>
I put a LinearLayout before the button, and added android:gravity="bottom" to the LinearLayout. This should do it.
Remove your top layout's right, left and bottom padding:
<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="#drawable/sfondologin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
Related
I have tried placing image(imageBottom) below scroll view(scrollView) but it is overlapping left bottom corner of scroll view.
I have also tried attribute layout_below in imageview but this trick dint worked.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/myLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.rohitkumar.androidtutorial.MainActivity">
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/imageIcon"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="#string/TextString"
android:textSize="32sp" />
<ScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/textView1"
android:layout_marginBottom="30dp"
android:layout_marginTop="10dp">
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/longText"
android:textSize="20sp" />
</ScrollView>
<ImageView
android:id="#+id/imageIcon"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:contentDescription=""
app:srcCompat="#drawable/course1" />
<ImageView
android:id="#+id/imageBottom"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:contentDescription="#string/course_image"
android:src="#drawable/image_1" />
</RelativeLayout>
Create a relative layout and place the textview and image icon within it:
<RelativeLayout
android:id="#+id/rl1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
>
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/imageIcon"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="#string/TextString"
android:textSize="32sp" />
<ImageView
android:id="#+id/imageIcon"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:contentDescription=""
app:srcCompat="#drawable/course1" />
</RelativeLayout
Add android:layout_above="#+id/imageBottom" and android:layout_below="#+id/rl1"in your scrollview
You want to scroll only textview than you dont need any scroll view,you can make textview scroll like this:
Just set the
android:maxLines = "AN_INTEGER"
android:scrollbars = "vertical"
properties of your TextView in your layout's xml file.
Then use:
yourTextView.setMovementMethod(new ScrollingMovementMethod());
in your code.
And Add android:layout_above="#+id/imageBottom" to your textView and android:layout_below="#+id/textView1" remove scroll view layout
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textView1"
android:layout_centerHorizontal="true"
android:layout_above="#+id/imageBottom"
android:gravity="center"
android:text="#string/TextString"
android:textSize="32sp" />
Try this out.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/myLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
>
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/imageIcon"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="hi"
android:textSize="32sp" />
<ScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_above="#+id/imageBottom"
android:layout_below="#+id/textView1"
android:layout_marginBottom="30dp"
android:layout_marginTop="10dp">
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="20sp" />
</ScrollView>
<ImageView
android:id="#+id/imageBottom"
android:layout_alignParentBottom="true"
android:layout_width="100dp"
android:layout_height="100dp"
/>
<ImageView
android:id="#+id/imageIcon"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:contentDescription=""
/>
</RelativeLayout>
#Rohit Kumar you just add this line in scroll view android:layout_above="#+id/imageBottom"and android:layout_below="#+id/textView1"
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/myLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.rohitkumar.androidtutorial.MainActivity">
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/imageIcon"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="Title"
android:textSize="32sp" />
<ScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/imageBottom"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/textView1"
android:layout_marginBottom="30dp"
android:layout_marginTop="10dp">
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="this is a simple paragraph that is meant to be nice and easy to type which is why there will be mommas no periods or any capital letters so i guess this means that it cannot really be considered a paragraph but just a series of run on sentences this should help you get faster at typing as im trying not to use too many difficult words in it although i think that i might start making it hard by including some more difficult letters I'm typing pretty quickly so forgive me for any mistakes i think that i will not just tell you a story about the time i went to the zoo and found"
android:textSize="20sp" />
</ScrollView>
<ImageView
android:id="#+id/imageIcon"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:contentDescription="test"
app:srcCompat="#mipmap/ic_launcher" />
<ImageView
android:id="#+id/imageBottom"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:src="#mipmap/ic_launcher" />
</RelativeLayout>
I am trying to implement a scrollview in one of my XML files but it doesnt seem to be working. It is cutting out the bottom 3 spinners and the last button in the XML. I guessed this is because I needed to scroll down to see them but I am unable to scroll?
Can anyone seem the issue?
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:fillViewport="true"
>
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<TextView
android:id="#+id/title"
android:text="New Recipe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"/>
<EditText
android:id="#+id/recipeName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/title"
android:hint="Enter Recipe Name"/>
<ListView
android:id="#+id/ingredientsList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/recipeName"
android:textColor="#000000"
android:layout_above="#+id/showIngredientDialog"
android:minHeight="150px">
</ListView>
<Button
android:id="#+id/showIngredientDialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Ingredient"
android:layout_above="#+id/showDirectionDialog"
android:layout_alignParentStart="true"
android:layout_marginBottom="145dp" />
<ListView
android:id="#+id/directionsList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:layout_above="#+id/showDirectionDialog"
android:layout_alignParentStart="true"
android:layout_marginBottom="37dp">
</ListView>
<Button
android:id="#+id/showDirectionDialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Direction"
android:layout_marginBottom="79dp"
android:layout_alignParentBottom="true"
android:layout_alignEnd="#+id/showIngredientDialog" />
<Spinner
android:id="#+id/timeSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/showDirectionDialog"
android:entries="#array/time"/>
<Spinner
android:id="#+id/dietarySpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:entries="#array/dietary"
android:layout_below="#+id/showDirectionDialog"
android:layout_toRightOf="#+id/timeSpinner" />
<Spinner
android:id="#+id/heatSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:entries="#array/heat"
android:layout_below="#+id/showDirectionDialog"
android:layout_toRightOf="#+id/dietarySpinner" />
<Button
android:id="#+id/saveRecipe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save Recipe"
android:layout_below="#+id/timeSpinner"
android:layout_alignParentBottom="true"
android:layout_alignEnd="#+id/showDirectionDialog"
android:layout_marginBottom="25dp" />
</RelativeLayout>
</ScrollView>
Your facing this issue because you are using ScrollView in which having ListView. Both having default scroll property which conflicting the issue. Check this SO post for resolving the issue.
Set the relativeLayout height to "wrap_content".
<?xml version="1.0" encoding="utf-8"?>
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<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">
<TextView
android:id="#+id/title"
android:text="New Recipe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"/>
<EditText
android:id="#+id/recipeName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/title"
android:hint="Enter Recipe Name"/>
<ListView
android:id="#+id/ingredientsList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/recipeName"
android:textColor="#000000"
android:layout_above="#+id/showIngredientDialog"
android:minHeight="150px">
</ListView>
<Button
android:id="#+id/showIngredientDialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Ingredient"
android:layout_above="#+id/showDirectionDialog"
android:layout_alignParentStart="true"
android:layout_marginBottom="145dp" />
<ListView
android:id="#+id/directionsList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:layout_above="#+id/showDirectionDialog"
android:layout_alignParentStart="true"
android:layout_marginBottom="37dp">
</ListView>
<Button
android:id="#+id/showDirectionDialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Direction"
android:layout_marginBottom="79dp"
android:layout_alignParentBottom="true"
android:layout_alignEnd="#+id/showIngredientDialog" />
<Spinner
android:id="#+id/timeSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/showDirectionDialog"
android:entries="#array/time"/>
<Spinner
android:id="#+id/dietarySpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:entries="#array/dietary"
android:layout_below="#+id/showDirectionDialog"
android:layout_toRightOf="#+id/timeSpinner" />
<Spinner
android:id="#+id/heatSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:entries="#array/heat"
android:layout_below="#+id/showDirectionDialog"
android:layout_toRightOf="#+id/dietarySpinner" />
<Button
android:id="#+id/saveRecipe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save Recipe"
android:layout_below="#+id/timeSpinner"
android:layout_alignParentBottom="true"
android:layout_alignEnd="#+id/showDirectionDialog"
android:layout_marginBottom="25dp" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
you can't put two scrolling widgets inside one another the will cause major issues even with normal scrolling
if there is no way to change this layout design please force a height to each listview but still the scroll will be buggy and you have to set extra margin on the side of list for the user to be able to scroll the parent scroll view
or try to break down the design if you can maybe tabs one for normal data and a tab for each list
Because views of total heigt not bigger than screen height.
You can see with coding custom height. I hope below code help you.
I just change listview height.
<?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:fillViewport="true"
>
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<TextView
android:id="#+id/title"
android:text="New Recipe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"/>
<EditText
android:id="#+id/recipeName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/title"
android:hint="Enter Recipe Name"/>
<ListView
android:id="#+id/ingredientsList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/recipeName"
android:textColor="#000000"
android:layout_above="#+id/showIngredientDialog"
android:minHeight="150px">
</ListView>
<Button
android:id="#+id/showIngredientDialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Ingredient"
android:layout_above="#+id/showDirectionDialog"
android:layout_alignParentStart="true"
android:layout_marginBottom="145dp" />
<ListView
android:id="#+id/directionsList"
android:layout_width="fill_parent"
android:layout_height="1000dp"
android:textColor="#000000"
android:layout_above="#+id/showDirectionDialog"
android:layout_alignParentStart="true"
android:layout_marginBottom="37dp">
</ListView>
<Button
android:id="#+id/showDirectionDialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Direction"
android:layout_marginBottom="79dp"
android:layout_alignParentBottom="true"
android:layout_alignEnd="#+id/showIngredientDialog" />
<Spinner
android:id="#+id/timeSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/showDirectionDialog"
/>
<Spinner
android:id="#+id/dietarySpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/showDirectionDialog"
android:layout_toRightOf="#+id/timeSpinner" />
<Spinner
android:id="#+id/heatSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/showDirectionDialog"
android:layout_toRightOf="#+id/dietarySpinner" />
<Button
android:id="#+id/saveRecipe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save Recipe"
android:layout_below="#+id/timeSpinner"
android:layout_alignParentBottom="true"
android:layout_alignEnd="#+id/showDirectionDialog"
android:layout_marginBottom="25dp" />
</RelativeLayout>
Recently I started practicing Android Development and I am stuck at a very basic problem. Since I am a beginner in this field, I am asking for your help.
<LinearLayout
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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MainActivity">
<TextView
android:text="Name1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:textSize="18sp"
/>
<EditText
android:id="#+id/player_name"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="#integer/abc_max_action_buttons"
/>
<TextView
android:text="Name2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:textSize="18sp"
/>
<EditText
android:id="#+id/player_name"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="#integer/abc_max_action_buttons"
/>
</LinearLayout>
In this XML scheme, I am trying to put a text followed by text-space and repeating it again.
e.g. Name1 ___________________ //Next Line//
Name2 ___________________
But the problem is that Name2 is not going into the next line and staying in the same line .
Please tell me how to fix it.
Thanks in advance
In these type of scenarios I create a layout within a layout.
So each line of yours will be a layout and hence. You can only those elements in that line.
<?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" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="57dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/lblName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_gravity="left"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:text="Name"
android:textSize="20dp" />
<EditText
android:id="#+id/txtName"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:ems="10"
android:gravity="left" >
<requestFocus />
</EditText>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="57dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/lblName1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_gravity="left"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:text="Name"
android:textSize="20dp" />
<EditText
android:id="#+id/txtName1"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:ems="10"
android:gravity="left" >
</EditText>
</RelativeLayout>
You need to add orientation = vertical and I've changed your widths to match parent.
<LinearLayout 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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<TextView
android:layout_width="match_parent" android:layout_height="wrap_content"
android:text="Name1" android:textColor="#000000" android:textSize="18sp"/>
<EditText
android:id="#+id/player_name1" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="#integer/abc_max_action_buttons"/>
<TextView
android:layout_width="match_parent" android:layout_height="wrap_content"
android:text="Name2" android:textColor="#000000" android:textSize="18sp"/>
<EditText
android:id="#+id/player_name2" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="#integer/abc_max_action_buttons"/>
</LinearLayout>
Not sure exactly what height space you want, but have used your dimensions.
In my application, i want to display one TextView in bottom of the Screen with copyright note.
I used following xml code.
In my code TextView couldn't display in bottom of the screen.
I suppose I'm not doing right but I know why.
I would greatly appreciate your help.
Thanks in advance.
<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="#bfceee"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="70dp"
android:text="#string/name"
android:textSize="20sp"
android:textStyle="bold" />
<EditText
android:id="#+id/rt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/btnSend"
android:layout_alignRight="#+id/btnSend"
android:layout_gravity="center_horizontal"
android:layout_marginTop="140dp"
android:inputType=""
android:textColor="#000"
android:textSize="20sp" >
</EditText>
<Button
android:id="#+id/btnSend"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="210dp"
android:background="#EAEAAE"
android:text="#string/send"
android:textColor="#5C3317"
android:textSize="20sp"
android:textStyle="bold"
android:width="150sp" />
<TextView
android:id="#+id/Copyright"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:textStyle="bold" >
</TextView>
</RelativeLayout>
Use this android:layout_below="#+id/btnSend".
<TextView
android:id="#+id/Copyright"
android:layout_below="#+id/btnSend"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="Hi"
android:layout_marginTop="15dp"
android:textStyle="bold" >
</TextView>
If you want to bottom of the screen then use
android:layout_alignParentBottom="true"
Use this in textView instead of gravity-
android:layout_alignParentBottom="true"
Don't use gravity, use:
android:layout_alignParentBottom="true"
See RelativeLayout.LayoutParams for more information
Try this way,hope this will help you to solve your problem.
Here i have used LinearLayout instead of RelativeLayout becz i have seen top margin which not proper work on various devices so i have implement weight in LinearLayout.
<LinearLayout 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="#bfceee"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/name"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center">
<EditText
android:id="#+id/rt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000"
android:textSize="20sp" >
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center">
<Button
android:id="#+id/btnSend"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#EAEAAE"
android:text="#string/send"
android:textColor="#5C3317"
android:textSize="20sp"
android:textStyle="bold"
android:width="150sp" />
</LinearLayout>
</LinearLayout>
<TextView
android:id="#+id/Copyright"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textStyle="bold" >
</TextView>
</LinearLayout>
I want to have two buttons that is fixed on the bottom screen like a footer and other views won't make pass on it or overlap on the two buttons. It will just stay still on the bottom always. Sorry for my English. Please help me. Btw I cannot post images so it requires 10 reputation that's why I used online image viewing. Sorry for that.
Here is the screenshot of my work which is wrong
http://postimg.org/image/pzry53ey9/
As you can see the multiline edit text overlaps on the two buttons as well as the scrollview. How to fix that?
Here is my code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/ic_launcher" />
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true" />
<EditText
android:id="#+id/editText3"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="bottom" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Save" />
<Button
android:id="#+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
Try this way,hope this will help you to solve your problem.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/ic_launcher" />
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true" />
<EditText
android:id="#+id/editText3"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Save" />
<Button
android:id="#+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel" />
</LinearLayout>
</LinearLayout>
your layout is quite complex for a simple view but i have modified it to achieve what you want
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/relativeLayout1"
android:layout_marginBottom="5dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/ic_launcher" />
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true" />
<EditText
android:id="#+id/editText3"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="bottom" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Save" />
<Button
android:id="#+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel" />
</LinearLayout>
</RelativeLayout>
You don't need the RelativeLayout containing the LinearLayout that holds your buttons...get rid of the RelativeLayout and specify the LinearLayout like so:
<LinearLayout
android:id="#+id/buttons_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true" >
Next, since your parent Layout is RelativeLayout, you'll need to specify the positioning of your ScrollView containing the EditText:
<ScrollView
android:layout_above="#+id/buttons_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
Also, if you want the buttons to stay at the very bottom of your view then remove this line from the parent Layout:
android:paddingBottom="#dimen/activity_vertical_margin"
Hope this helps!
Your root layout file is relative layout. It allows overlapping of UI elements(z-index placement). So you need to provide the boundary for a view to extend. Assign a android:id= "#+id\relativeLayout" to your relative layout(bottom not root). Then in your scrollview put
android:layout_above="#+id\relativeLayout". Follow similar approach for other views.