I have kept my RelativeLayout inside a ScrollView but still it is not becoming scrollable and also i am not getting extra space to drag and drop more view in my layout. plzz help..
I am new to android any answers will be a great help for me....Thanks in Advance.......
<?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
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#b8fce8"
android:gravity="bottom" >
<TextView
android:id="#+id/txtDocProfile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="Doctor Profile"
android:gravity="center_horizontal"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/lblDocName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/txtDocProfile"
android:layout_marginTop="14dp"
android:text="Name :"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/txtDocName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/lblDocName"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/tetSpecilazation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/lblDocSpeciality"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/lblDocQualification"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/tetSpecilazation"
android:layout_marginTop="22dp"
android:text="Qualification :"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/txtDocQualification"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/lblDocQualification"
android:layout_below="#+id/lblDocQualification"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/lblDocSpeciality"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/txtDocName"
android:layout_marginTop="16dp"
android:text="Specilization :"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/lblAddress1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="Address 1 :"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/txtDocQualification"
android:layout_alignParentRight="true"
android:layout_below="#+id/lblAddress1"
android:gravity="top|left"
android:inputType="textMultiLine"
android:lines="4"
android:scrollHorizontally="false"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/lblContact"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/textView1"
android:layout_marginTop="27dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/lblMobile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_alignRight="#+id/txtDocQualification"
android:layout_below="#+id/lblContact"
android:text="Mobile No :"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/txtDocMobNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/lblMobile"
android:layout_alignBottom="#+id/lblMobile"
android:layout_toRightOf="#+id/lblMobile"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="#+id/btnCallMob"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/txtDocMobNo"
android:layout_marginRight="16dp"
android:text="Call" />
<TextView
android:id="#+id/lblDocPhone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/lblMobile"
android:layout_alignParentBottom="true"
android:text="Landline "
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/txtDocPhoneNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#+id/lblMobile"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="#+id/btnCallPhone"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/btnCallMob"
android:layout_alignParentBottom="true"
android:text="Call" />
</RelativeLayout>
</ScrollView>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<!--put here your button and all other-->
</LinearLayout>
</ScrollView>
</RelativeLayout>
Actually it not works because of this
android:layout_alignParentBottom="true"
So the last component laid on bottom of Relative Layout and not stretching anywhere
If you want to stretch your Relative Layout try to add your component stack vertically each other with
android:layout_below="#+id/yourComponentBefore"
i give it example
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#b8fce8"
android:gravity="bottom" >
<TextView
android:id="#+id/ComponentOne"
android:layout_width="match_parent"
android:layout_height="450dp"
android:background="#CFCFCF" />
<TextView
android:id="#+id/ComponentTwo"
android:layout_width="match_parent"
android:layout_height="450dp"
android:layout_below="#+id/ComponentOne"
android:background="#FFFFFF" />
<TextView
android:id="#+id/ComponentThree"
android:layout_width="match_parent"
android:layout_height="450dp"
android:layout_below="#+id/ComponentTwo"
android:background="#000000" />
</RelativeLayout>
Related
My scrollview on my .xml is working but it's overlapping on the toolbar I can't press back on the hierarchy anymore and also I just updated my android studio to 2.2 Beta idk if this is the problem.
Here it is.
<?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" >
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.kun.carkila.DetailActivity"
tools:showIn="#layout/activity_detail">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/etResDate"
android:editable="false"
android:hint="Reservation Date"
android:layout_below="#+id/etPickup"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/etResTime"
android:editable="false"
android:hint="Reservation Time"
android:layout_below="#+id/etResDate"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/etPickup"
android:hint="Pickup Location"
android:layout_below="#+id/tvPoster"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="22dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/etReturnTime"
android:editable="false"
android:hint="Return Time"
android:layout_below="#+id/etReturnDate"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rent"
android:id="#+id/btnRent"
android:layout_below="#+id/etReturnTime"
android:layout_centerHorizontal="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ivImage"
android:src="#android:drawable/star_big_on"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/tvCarModel"
android:layout_below="#+id/ivImage"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/tvCarType"
android:layout_below="#+id/tvCarModel"
android:layout_alignLeft="#+id/tvCarModel"
android:layout_alignStart="#+id/tvCarModel" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/tvCapacity"
android:layout_below="#+id/tvCarType"
android:layout_alignLeft="#+id/tvCarType"
android:layout_alignStart="#+id/tvCarType" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/tvFuelType"
android:layout_below="#+id/tvCapacity"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/tvPoster"
android:layout_below="#+id/tvPlateNumber"
android:layout_alignLeft="#+id/tvPlateNumber"
android:layout_alignStart="#+id/tvPlateNumber" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/tvPlateNumber"
android:layout_below="#+id/tvFuelType"
android:layout_alignLeft="#+id/tvFuelType"
android:layout_alignStart="#+id/tvFuelType" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/etReturnDate"
android:editable="false"
android:hint="Return Date"
android:layout_below="#+id/etResTime"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
Remove this app:layout_behavior="#string/appbar_scrolling_view_behavior" from Relative Layout.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.kun.carkila.DetailActivity"
tools:showIn="#layout/activity_detail">
<?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">
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.kun.carkila.DetailActivity">
<EditText
android:id="#+id/etResDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/etPickup"
android:editable="false"
android:hint="Reservation Date" />
<EditText
android:id="#+id/etResTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/etResDate"
android:editable="false"
android:hint="Reservation Time" />
<EditText
android:id="#+id/etPickup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/tvPoster"
android:layout_marginTop="22dp"
android:ems="10"
android:hint="Pickup Location"
android:inputType="textPersonName" />
<EditText
android:id="#+id/etReturnTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/etReturnDate"
android:editable="false"
android:hint="Return Time" />
<Button
android:id="#+id/btnRent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/etReturnTime"
android:layout_centerHorizontal="true"
android:text="Rent" />
<ImageView
android:id="#+id/ivImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="#android:drawable/star_big_on" />
<TextView
android:id="#+id/tvCarModel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/ivImage"
android:layout_centerHorizontal="true"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/tvCarType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/tvCarModel"
android:layout_alignStart="#+id/tvCarModel"
android:layout_below="#+id/tvCarModel"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/tvCapacity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/tvCarType"
android:layout_alignStart="#+id/tvCarType"
android:layout_below="#+id/tvCarType"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/tvFuelType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tvCapacity"
android:layout_centerHorizontal="true"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/tvPoster"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/tvPlateNumber"
android:layout_alignStart="#+id/tvPlateNumber"
android:layout_below="#+id/tvPlateNumber"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/tvPlateNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/tvFuelType"
android:layout_alignStart="#+id/tvFuelType"
android:layout_below="#+id/tvFuelType"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/etReturnDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/etResTime"
android:editable="false"
android:hint="Return Date" />
</RelativeLayout>
</ScrollView>
check if this helps
Please do something like the XML code below or just simply add your EditText/TextView component in between NestedScrollView.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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/addtimesheetlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.kun.carkila.DetailActivity"
android:orientation="vertical">
<android.support.v4.widget.NestedScrollView
android:id="#+id/scrollableview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<!--Add your EditText here-->
</LinearLayout><!--Main layout ends-->
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
When I use fill_parent on the width of my EditText, the autofill of AndroidStudio shows it crossed out. If I still try using it it messes up the positioning of the EditText by throwing it out of the screen. I just want to have a simple text field and next to it an input text field which occupies the remaining of the screen.
Here is the 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: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.kristmiha.registrationtest.MainActivity">
<TextView
android:id="#+id/headline1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:gravity="center"
android:text="#string/hello"
android:textSize="32sp" />
<TextView
android:id="#+id/headline2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#+id/headline1"
android:text="#string/register_here"
android:gravity="center"
android:textSize="24sp" />
<TextView
android:id="#+id/tvFirstName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First Name"
android:layout_below="#+id/headline2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="20dp" />
<EditText
android:id="#+id/etFirstName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/tvFirstName"
android:layout_toRightOf="#+id/tvFirstName"
android:layout_toEndOf="#+id/tvFirstName" />
EDIT: Here is the position of the text field:
You should try this. With some modification you can achieve what you want.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/textView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/textView2"
android:layout_below="#+id/textView"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/textView3"
android:layout_alignBottom="#+id/editText2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText2"
android:layout_below="#+id/textView2"
android:layout_toRightOf="#+id/textView3"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/textView4"
android:layout_alignBottom="#+id/editText3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText3"
android:layout_below="#+id/textView3"
android:layout_toRightOf="#+id/textView4"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
try this
<TextView
android:id="#+id/headline1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:gravity="center"
android:text="Hellow world!!"
android:textSize="32sp" />
<TextView
android:id="#+id/headline2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#+id/headline1"
android:text="Register Here"
android:gravity="center"
android:textSize="24sp" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/headline2"
android:layout_marginTop="20dp">
<TextView
android:id="#+id/tvFirstName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First Name"
/>
<EditText
android:id="#+id/etFirstName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
/>
</LinearLayout>
In relative layout
<TextView
android:id="#+id/tvFirstName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First Name"
android:layout_below="#+id/headline2"
android:layout_marginTop="20dp"
android:layout_alignBottom="#+id/etFirstName"
android:gravity="center"
/>
<EditText
android:id="#+id/etFirstName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
android:layout_below="#+id/headline2"
android:layout_toRightOf="#+id/tvFirstName"
android:layout_toEndOf="#+id/tvFirstName"
android:layout_marginTop="20dp"
/>
fill_parent value is deprecated use match_parent
Here you can see more and here more
Special value for the height or width requested by a View. FILL_PARENT
means that the view wants to be as big as its parent, minus the
parent's padding, if any. This value is deprecated starting in API
Level 8 and replaced by MATCH_PARENT.
For your problem : you should use this:
<?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"
tools:context="test.com.temp.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="label"
android:id="#+id/labelOne"
android:layout_alignBaseline="#+id/input"
/>
<EditText
android:id="#+id/input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/labelOne"
android:layout_toEndOf="#+id/labelOne"
/>
</RelativeLayout>
I want to set list view between two hardcoded items. I can't leave the height value blank in listView, cause it's disappear. I try with wrap/fill.. but all this things making my listView fill whole layout. Here is my code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ListView
android:id="#+id/choose_list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/relativeLayout1" >
</ListView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:background="#drawable/buton_style" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="90dp" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/addToBasketName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Produkty:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/choose_produkty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Do zapłaty:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/choose_do_zaplaty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
<Button
android:id="#+id/addToBasket"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="Do kasy" />
</RelativeLayout>
How would you solve this problem?
By default , all your Views will be placed at the top left corner in your RelativeLayout. So you will usually want to add layout_below or layout_top to your component.
For a more detail description for RelativeLayout, see this
Try this one
<ListView
android:id="#+id/choose_list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/relativeLayout1"
android:layout_below="#+id/textView1" >
Use a LinearLayout as the outmost container, and setthis to the ListView:
layout_height="0px
layout_weight="1"
// try this way
<?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="wrap_content"
android:padding="5dp"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ListView
android:id="#+id/choose_list_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="5dp"
android:layout_weight="1">
</ListView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_weight="1">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/addToBasketName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Produkty:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/choose_produkty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Do zapłaty:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/choose_do_zaplaty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
<Button
android:id="#+id/addToBasket"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Do kasy" />
</LinearLayout>
</LinearLayout>
I am trying to create an layout as shown in the figure.
In that image shipped to is attached to the border of the layout. how to overlap like that.
Here is the XML I am using to create that
<RelativeLayout
android:id="#+id/shipped_to_header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/address_blue_border" >
<TextView
android:id="#+id/tv_shipped_to"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/homebackground"
android:text="Shipped To"
android:textColor="#android:color/white" />
<TextView
android:id="#+id/tv_door_no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_shipped_to"
android:text="22"
android:textColor="#android:color/black" />
<TextView
android:id="#+id/tv_address_line1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_door_no"
android:text="Delhi, India"
android:textColor="#android:color/black" />
<TextView
android:id="#+id/tv_address_line2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_address_line1"
android:text="Swindon Senegal BS32 8FE"
android:textColor="#android:color/black" />
</RelativeLayout>
Try this
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="8dp"
android:background="#android:color/holo_blue_bright"
android:orientation="vertical"
android:padding="10dp" >
<TextView
android:id="#+id/tv_door_no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="22" />
<TextView
android:id="#+id/tv_address_line1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Delhi" />
<TextView
android:id="#+id/tv_address_line2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some more dara" />
</LinearLayout>
<TextView
android:id="#+id/tv_shipped_to"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Ship To"
android:background="#android:color/holo_blue_dark"
android:layout_marginLeft="15dp"
/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:background="#android:color/white">
<!-- This is the main content -->
<RelativeLayout
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_margin="15dp" android:background="#drawable/frame"
android:orientation="vertical" android:padding="20dp">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="Main Content" android:layout_centerInParent="true" />
</RelativeLayout>
<!-- This is the title label -->
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:background="#android:color/white" android:padding="5dp"
android:text="Testing"
android:layout_marginLeft="30dp" android:textColor="#android:color/black" />
</RelativeLayout>
You can have your answer at here and here
To obtain a layout similar to the one it's in the image you have to use command android:layout_margin with negative values.
Here is an example:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="70dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="TextView" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="TextView" />
</RelativeLayout>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/relativeLayout1"
android:layout_alignParentLeft="true"
android:layout_marginBottom="-10dp"
android:text="TextView" />
</RelativeLayout>
Your image is a bit toooo small. Anyway, for that, use RelativeLayout.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="0dp" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_margin="20dp"
android:background="#ccff00"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<!-- Your other TextViews -->
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/linearLayout1"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:background="#ccffff"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
Hello I need to set scroll view in following code,and set after first relative layout but it gives me :
main.xml: IllegalStateException: ScrollView can host only one direct child
that means i cant use scrollview in multiple layout child.So how can i use scroll view inside first relative layout and cover with all inner relative layout.
Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="#drawable/page1_11"
android:layout_height="fill_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/login_rellay_01" android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView android:layout_height="wrap_content"
android:layout_width="match_parent" android:src="#drawable/page1_1"
android:id="#+id/imageView1" android:layout_alignParentLeft="true" />
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content" android:text="Shanesh COLORS App"
android:textSize="13dp" android:textStyle="bold" android:textColor="#49515F"
android:layout_centerInParent="true" />
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_below="#+id/login_rellay_01" android:id="#+id/login_rellay_02"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<ImageView android:layout_height="wrap_content"
android:layout_width="wrap_content" android:src="#drawable/page1_4"
android:id="#+id/imageView1" android:layout_centerHorizontal="true" />
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content" android:text="SIGN IN"
android:textSize="13dp" android:textStyle="bold" android:textColor="#FFFFFF"
android:layout_centerInParent="true" />
<Button android:layout_height="wrap_content"
android:layout_width="wrap_content" android:background="#drawable/page1_2"
android:layout_centerVertical="true" android:layout_marginLeft="10dp" />
<Button android:layout_height="wrap_content"
android:layout_width="wrap_content" android:background="#drawable/page1_3"
android:layout_centerVertical="true" android:layout_marginRight="10dp"
android:layout_alignParentRight="true" />
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/login_rellay_03" android:layout_below="#+id/login_rellay_02"
android:layout_width="match_parent" android:layout_height="wrap_content">
<ImageView android:layout_height="wrap_content"
android:layout_width="match_parent" android:src="#drawable/page1_5"
android:id="#+id/imgv_page1_5" android:layout_alignParentLeft="true" />
<!-- <ImageView android:layout_height="wrap_content" android:layout_below="#+id/imgv_page1_5"
android:layout_marginTop="1dp" android:layout_width="match_parent" android:src="#drawable/page1_6"
android:id="#+id/imgv_page1_6" android:layout_alignParentLeft="true" /> -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/login_rellay_03" android:layout_centerInParent="true"
android:layout_below="#+id/login_rellay_02" android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content" android:text="SIGN IN "
android:textSize="13dp" android:id="#+id/login_txvx_dwbnr_1"
android:textStyle="bold" android:textColor="#000000"
android:layout_marginLeft="10dp" android:layout_centerVertical="true" />
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content" android:text="with your "
android:id="#+id/login_txvx_dwbnr_2" android:layout_toRightOf="#+id/login_txvx_dwbnr_1"
android:textSize="13dp" android:layout_centerVertical="true"
android:textColor="#000000" />
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content" android:text="Shanesh Colors"
android:id="#+id/login_txvx_dwbnr_3" android:layout_toRightOf="#+id/login_txvx_dwbnr_2"
android:textSize="13dp" android:textStyle="bold"
android:layout_centerVertical="true" android:textColor="#000000" />
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content" android:text=" App Account "
android:id="#+id/login_txvx_dwbnr_4" android:layout_toRightOf="#+id/login_txvx_dwbnr_3"
android:textSize="13dp" android:layout_centerVertical="true"
android:textColor="#000000" />
</RelativeLayout>
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/login_rellay_04" android:layout_marginTop="1dp"
android:gravity="center" android:layout_below="#+id/login_rellay_03"
android:layout_width="match_parent" android:layout_height="wrap_content">
<ImageView android:layout_height="180dp"
android:layout_width="306dp" android:background="#FFFFFF" android:id="#+id/imgv_page1_6"
android:layout_centerInParent="true" />
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/login_rellay_04" android:layout_width="match_parent"
android:layout_height="wrap_content" android:gravity="center">
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content" android:text="User Name:"
android:id="#+id/login_txvx_dwbnr_5" android:layout_toRightOf="#+id/login_txvx_dwbnr_1"
android:textSize="11dp" android:layout_centerVertical="true"
android:textColor="#49515F" />
<EditText android:layout_height="40dp" android:layout_width="220dp"
android:layout_marginTop="10dp" android:layout_toRightOf="#+id/login_txvx_dwbnr_5" />
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/login_rellay_05" android:layout_width="match_parent"
android:layout_height="wrap_content" android:gravity="center"
android:layout_below="#+id/login_rellay_04">
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text=" Password:"
android:id="#+id/login_txvx_dwbnr_5"
android:layout_toRightOf="#+id/login_txvx_dwbnr_1"
android:textSize="11dp"
android:layout_centerVertical="true"
android:textColor="#49515F" />
<EditText android:layout_height="40dp" android:layout_width="220dp"
android:layout_alignParentTop="true" android:layout_marginTop="10dp"
android:layout_toRightOf="#+id/login_txvx_dwbnr_5" />
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/login_rellay_06"
android:layout_marginTop="3dp"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_below="#+id/login_rellay_05"
android:layout_width="match_parent">
<TextView android:layout_height="wrap_content"
android:textColor="#000000"
android:text="No Account?"
android:textStyle="bold"
android:textSize="11dp"
android:id="#+id/login_txvx_dwbnr_9"
android:layout_width="wrap_content"/>
<TextView android:text="Sign Up"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="#+id/login_txvx_signup_account"
android:textColor="#8891A2"
android:textStyle="bold"
android:layout_toRightOf="#+id/login_txvx_dwbnr_9"
android:textSize="11dp"
/></RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/login_rellay_07"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_below="#+id/login_rellay_06"
android:layout_width="match_parent">
<CheckBox android:layout_height="wrap_content"
android:id="#+id/checkBox1"
android:layout_below="#+id/login_txvx_signup_account"
android:layout_width="wrap_content"
android:textColor="#49515F"
android:textSize="11dp"
android:layout_marginLeft="10dp"
android:text=" Remember User Name and Password?"
/>
</RelativeLayout>
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/login_rellay_08"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_marginTop="60dp"
android:layout_below="#+id/login_rellay_04"
android:layout_width="match_parent">
<ImageView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="#drawable/page1_8"
/>
</RelativeLayout>
</RelativeLayout>
You make the outer most element the scrollview, which will give only one child your top-level relativelayout.