Search code examples
androidandroid-activityandroid-scrollviewandroid-relativelayout

scrollview in RelativeLayout --android


i have one RelativeLayout and i have some views(image and edittexts) and now i want to use scrollview.this is a my xml code

<RelativeLayout
    android:id="@+id/relativeLayout2"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_marginTop="70dp" >

    <ImageView
        android:id="@+id/loginbtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/passwordfild"
        android:layout_alignRight="@+id/passwordfild"
        android:layout_below="@+id/passwordfild"
        android:layout_marginTop="28dp"
        android:background="@drawable/login"
        android:textColor="#ffffff" />

    <EditText
        android:id="@+id/passwordfild"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/namefild"
        android:layout_alignRight="@+id/namefild"
        android:layout_centerVertical="true"
        android:background="@drawable/edittextbackground"
        android:ems="10"
        android:hint="პაროლი"
        android:inputType="textPassword"
        android:paddingLeft="15dp"
        android:textColorHint="#e2e0e0" >

        <requestFocus />
    </EditText>

    <EditText
        android:id="@+id/namefild"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/passwordfild"
        android:layout_marginBottom="42dp"
        android:layout_marginLeft="175dp"
        android:layout_marginRight="175dp"
        android:background="@drawable/edittextbackground"
        android:ems="10"
        android:hint="სახელი"
        android:paddingLeft="15dp"
        android:textColorHint="#e2e0e0" >

        <requestFocus />
    </EditText>

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/namefild"
        android:layout_alignLeft="@+id/namefild"
        android:layout_alignRight="@+id/namefild"
        android:layout_marginBottom="100dp"
        android:background="@drawable/icon" />
</RelativeLayout>

also i added

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="70dp" >

and i inserted my relative layout inside my scrollview but design has changed.i have no idea what am i doing wrong if anyone knows solution please help me


Solution

  • do like this,

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainlayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#E0FFFF" >
    
    <TextView
        android:id="@+id/tv1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="15dp"
        android:text="Portal Trading Ltd."
        android:textSize="18sp"
        android:textStyle="italic" />
    
    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tvSackNo"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="16dp"
        android:text="Santa Sacks"
        android:textSize="40sp" />
    
    <Button
        android:id="@+id/btnEdit"
        android:layout_width="100dp"
        android:layout_height="60dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_marginRight="21dp"
        android:text="Edit"
        android:textSize="25sp" />
    
    <Button
        android:id="@+id/btnConfirm"
        android:layout_width="100dp"
        android:layout_height="60dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="21dp"
        android:text="Confirm"
        android:textSize="21sp" />
    
    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/textView2"
        android:gravity="center"
        android:text="Printed Name Details"
        android:textSize="22sp" />
    
    <TextView
        android:id="@+id/tvExtraCharge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView3"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="5dp"
        android:text="Confirmation Page"
        android:textSize="12sp" />
    
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/btnEdit"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/tvExtraCharge"
        android:fillViewport="true"
        android:orientation="vertical" >
    
        <LinearLayout
            android:id="@+id/sackscontainer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:gravity="center"
            android:orientation="vertical" >
    
        </LinearLayout>
    </ScrollView>