I need move up the button "Choose a picture" I try with margin-button but doesn't work. Look the picture and the code. Any help? I dont know how solve this problem. Maybe Padding, but I tried and doesn't work too.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" style="#style/activity_main" android:background="#FFFFFF">
<ScrollView android:layout_width="match_parent" android:layout_height="match_parent">
<LinearLayout android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/RelativeLayout">
<ImageView
android:layout_width="130dp"
android:layout_marginTop="50dp"
android:layout_height="140dp"
android:id="#+id/imgProfile"
android:adjustViewBounds="true"
android:layout_centerHorizontal="true"
android:src="#drawable/profile_picture"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/imgProfileBackground"
android:adjustViewBounds="true"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"
android:src="#drawable/background_profile"/>
<Button
android:layout_width="wrap_content"
android:layout_height="30dp"
android:text="#string/choose_picture"
android:id="#+id/buttonSelectPicture"
android:background="#drawable/btn_change_picture"
android:textColor="#FFFFFF"
android:layout_gravity="center_horizontal|center"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginBottom="25dp"/>
</RelativeLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="119dp"
android:weightSum="1"
android:layout_marginTop="15dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.76"
android:baselineAligned="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:id="#+id/textView"
android:layout_weight="0.06"
android:layout_marginLeft="20dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/name"
android:layout_weight="0.33"
android:layout_marginRight="10dp"
android:background="#android:color/transparent"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="42dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Last Name"
android:id="#+id/textView2"
android:layout_weight="0.28"
android:layout_marginLeft="20dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/lastName"
android:layout_weight="3.98"
android:layout_marginRight="10dp"
android:background="#android:color/transparent"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="0.88">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Phone"
android:id="#+id/textView3"
android:layout_weight="0.01"
android:layout_marginLeft="20dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="36dp"
android:id="#+id/phone"
android:layout_weight="0.06"
android:layout_marginRight="10dp"
android:background="#android:color/transparent"/>
</LinearLayout>
</LinearLayout>
<Button
android:layout_width="fill_parent"
android:layout_height="40dp"
android:text="#string/upload"
android:id="#+id/updateButton"
android:background="#drawable/btn_save_changes"
android:textColor="#FFFFFF"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"/>
<RelativeLayout android:orientation="vertical" android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</RelativeLayout>
</LinearLayout>
</ScrollView>
The line that has layout_alignParentBottom is forcing the button to stay at the bottom of the parent element, no matter how you set the margins.
You can take out the line with android:layout_alignParentBottom, and replace that line with android:layout_below"#+id/imgProfile". Then you will be able to use android:layout_marginTop successfully.
Here is an example of the corrected code for the layout that you want:
<Button
android:layout_width="match_parent"
android:layout_height="30dp"
android:text="choose picture"
android:id="#+id/buttonSelectPicture"
android:background="#android:color/holo_blue_light"
android:textColor="#FFFFFF"
android:layout_gravity="center_horizontal|center"
android:layout_below="#+id/imgProfile"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginBottom="25dp"/>
Related
I got a RelativeLayout and inside there are two LinearLayouts side by side. Now I want that the right one has a minimum width of 125dp. So when the left LinearLayout gets too big, it should stop before the other LinearLayout and not push that one away.
How can I achieve this? This is my current approach:
Layout:
<?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"
android:id="#+id/item_list_item"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp">
<ImageButton
android:id="#+id/basket_item_list_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#android:color/transparent"
android:minWidth="50dp"
android:minHeight="50dp"
app:srcCompat="#drawable/ic_garbage"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_toRightOf="#+id/basket_item_list_delete"
android:layout_toEndOf="#+id/basket_item_list_delete">
<LinearLayout
android:id="#+id/basket_item_list_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:orientation="vertical">
<TextView
android:id="#+id/basket_item_list_itemname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:text="ItemName"
android:textColor="#color/generalText"
android:textSize="18sp" />
<TextView
android:id="#+id/basket_item_list_options"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:text="Options"/>
</LinearLayout>
<LinearLayout
android:id="#+id/priceLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="125dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:orientation="vertical"
android:layout_toRightOf="#id/basket_item_list_description">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="#+id/basket_item_list_increment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/basket_item_list_count"
android:layout_toStartOf="#+id/basket_item_list_count"
android:minWidth="45dp"
android:minHeight="45dp"
android:text="+"
android:textSize="20sp"
android:textColor="#color/colorPrimary"
android:background="#android:color/transparent" />
<TextView
android:id="#+id/basket_item_list_count"
android:layout_width="35dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="false"
android:layout_alignParentRight="false"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/basket_item_list_decrement"
android:layout_toStartOf="#+id/basket_item_list_decrement"
android:gravity="center_horizontal"
android:text="nx"
android:textColor="#color/generalText"
android:textSize="14sp" />
<Button
android:id="#+id/basket_item_list_decrement"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:minWidth="45dp"
android:minHeight="45dp"
android:text="–"
android:textSize="20sp"
android:textColor="#color/colorPrimary"
android:background="#android:color/transparent" />
</RelativeLayout>
<TextView
android:id="#+id/basket_item_list_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="50dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:text="1€"
android:gravity="right"
android:layout_gravity="right"
android:textColor="#color/generalText"
android:textSize="14sp" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
I want to have it like this:
But this is what happens, when the left LinearLayout gets too big:
Try this
<?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"
android:id="#+id/item_list_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<ImageButton
android:id="#+id/basket_item_list_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:background="#android:color/transparent"
android:minHeight="50dp"
android:minWidth="50dp"
app:srcCompat="#drawable/ic_menu_gallery" />
<LinearLayout
android:id="#+id/basket_item_list_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:paddingBottom="10dp"
android:paddingTop="10dp">
<TextView
android:id="#+id/basket_item_list_itemname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:text="ItemName"
android:textColor="#color/colorPrimary"
android:textSize="18sp" />
<TextView
android:id="#+id/basket_item_list_options"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:text="Options" />
</LinearLayout>
<LinearLayout
android:id="#+id/priceLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_gravity="right"
android:gravity="right"
android:minWidth="125dp"
android:orientation="vertical"
android:paddingBottom="10dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<Button
android:id="#+id/basket_item_list_increment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:minHeight="45dp"
android:minWidth="45dp"
android:text="+"
android:textColor="#color/colorPrimary"
android:textSize="20sp" />
<TextView
android:id="#+id/basket_item_list_count"
android:layout_width="35dp"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="nx"
android:textColor="#color/colorPrimary"
android:textSize="14sp" />
<Button
android:id="#+id/basket_item_list_decrement"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:minHeight="45dp"
android:minWidth="45dp"
android:text="–"
android:textColor="#color/colorPrimary"
android:textSize="20sp" />
</LinearLayout>
<TextView
android:id="#+id/basket_item_list_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:gravity="center"
android:minWidth="50dp"
android:text="1€"
android:textColor="#color/colorPrimary"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
Let try this ,
It will divide a screen Half and Half.
<LinearLayout
android:id="#+id/priceLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/priceLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight=".5"
android:orientation="vertical">
///Your views
</LinearLayout>
<LinearLayout
android:id="#+id/priceLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight=".5"
android:orientation="vertical">
///Your views
</LinearLayout>
</LinearLayout>
If You want first Wrap another one take remaining width take this
<LinearLayout
android:id="#+id/priceLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/priceLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
///Your views
</LinearLayout>
<LinearLayout
android:id="#+id/priceLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
///Your views
</LinearLayout>
</LinearLayout>
I am designing my android project on android studio. I used horizontal Linear Layout however it looks exactly the same as I wanted to be in Nexus 5, when I run the project on Nexus S, the view distorted. How can I fix this?
In nexus 5 view,
In nexus S view,
My xml file,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="89dp"
android:layout_height="97dp"
android:layout_marginTop="10dp"
android:id="#+id/imageView3"
android:src="#drawable/photo"
android:layout_above="#+id/textView5"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Duygu Yeşim"
android:textColor="#color/blue"
android:id="#+id/textView5"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textStyle="bold"
android:layout_above="#+id/imageView4"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp" />
<ImageView
android:layout_width="150dp"
android:layout_height="1dp"
android:background="#color/blue"
android:id="#+id/imageView4"
android:layout_above="#+id/linearLayout"
android:layout_centerHorizontal="true"
android:layout_marginBottom="14dp"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Kullanıcı Adı : "
android:id="#+id/textView8"
android:textColor="#color/blue"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="dygysm"
android:id="#+id/textView9"
android:textColor="#color/light_blue"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="3dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="E-mail Adresi :"
android:id="#+id/textView10"
android:textColor="#color/blue"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="#+id/editText"
android:background="#drawable/edit_design2"
android:hint="duygu.yesim#hotmail.com"
android:textSize="12sp"
android:textColorHint="#color/blue"
android:layout_marginLeft="4dp"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="3dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Doğum Tarihi : "
android:id="#+id/textView11"
android:textColor="#color/blue"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/dogum_tarihi"
android:layout_marginRight="5dp"
android:text="New Text"
android:textColor="#color/blue"
android:background="#drawable/edit_birtday_design"
android:drawableRight="#drawable/calendar"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayout"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
>
<ImageView
android:layout_width="310dp"
android:layout_height="1dp"
android:background="#color/light_blue"
android:id="#+id/imageView5"
android:layout_below="#+id/linearLayout"
android:layout_centerHorizontal="true" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bildirimler"
android:id="#+id/textView12"
android:textColor="#color/blue"/>
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:layout_marginLeft="200dp"
android:layout_gravity="end"
android:id="#+id/switch1" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="3dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Şifre Değiştirme"
android:id="#+id/textView13"
android:singleLine="true"
android:textColor="#color/blue"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageButton2"
android:src="#drawable/right_arrow_orange"
android:background="#00000000"
android:layout_marginLeft="190dp"
android:layout_marginTop="5dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="310dp"
android:layout_height="1dp"
android:id="#+id/imageView6"
android:background="#color/light_blue"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="87dp"
android:layout_height="27dp"
android:layout_marginTop="20dp"
android:layout_marginLeft="30dp"
android:background="#drawable/custom_kaydet_buton"
android:id="#+id/button" />
<Button
android:layout_width="87dp"
android:layout_height="27dp"
android:id="#+id/button2"
android:background="#drawable/custom_cikis_buton"
android:layout_marginTop="20dp"
android:layout_marginLeft="60dp"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
1) You will need to create multiple XML files as per screen sizes, Check this documentation - http://developer.android.com/guide/practices/screens_support.html
or
2) Put your Linear Layout in Horizontal Scroll View
Hope it will help :)
I've been using android studio and xml to design my application. I've wanted to make my "Hi,user", logout button, receipt button and cart move to the right of the screen. How should i change my xml to make it like this?
<LinearLayout
android:id="#+id/LinearLayout01"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="20dp">
<TextView
android:id="#+id/item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:textAppearance="?android:attr/textAppearanceMedium"
android:padding="2dp"
android:textColor="#33CC33" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Logout"
android:id="#+id/button"
android:layout_marginLeft="40dp"
android:layout_marginRight="10dp"
android:layout_weight="0.06" />
</LinearLayout>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="20dp">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Receipt"
android:id="#+id/receipt_button"
android:layout_marginLeft="40dp"
android:layout_marginRight="10dp"
android:layout_weight="0.06" />
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageButton
android:id="#+id/myButton"
android:layout_width="65dip"
android:layout_height="65dip"
android:scaleType="fitXY"
android:background="#null"
android:src="#drawable/cart"/>
<TextView
android:id="#+id/textOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#id/myButton"
android:layout_alignRight="#id/myButton"
android:text="0"
android:textColor="#FFF"
android:textSize="16sp"
android:textStyle="bold"
android:background="#drawable/badge_circle"/>
</RelativeLayout>
</LinearLayout>
Set "layout_gravity" as right to align right
<LinearLayout
android:id="#+id/LinearLayout01"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="right"
android:layout_marginTop="20dp">
<TextView
android:id="#+id/item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:textAppearance="?android:attr/textAppearanceMedium"
android:padding="2dp"
android:textColor="#33CC33" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Logout"
android:id="#+id/button"
android:layout_marginLeft="40dp"
android:layout_marginRight="10dp"
android:layout_weight="0.06" />
</LinearLayout>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="20dp">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Receipt"
android:id="#+id/receipt_button"
android:layout_marginLeft="40dp"
android:layout_marginRight="10dp"
android:layout_weight="0.06" />
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageButton
android:id="#+id/myButton"
android:layout_width="65dip"
android:layout_height="65dip"
android:scaleType="fitXY"
android:background="#null"
android:src="#drawable/cart"/>
<TextView
android:id="#+id/textOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#id/myButton"
android:layout_alignRight="#id/myButton"
android:text="0"
android:textColor="#FFF"
android:textSize="16sp"
android:textStyle="bold"
android:background="#drawable/badge_circle"/>
</RelativeLayout>
</LinearLayout>
I have tried LinearLayout inside which I put several textview. I completely use weights for each and every view. Problem arises when data becomes too much in lenght and textview not shows it completely. I also tried tabletlayout but that thing also not works beacuse ultimately tablelayout is inside linear layout having weight,so it doesn't grows beyond a certain limit. I want to know how can I make a activity scrollable with showing all data while using weights.
Use Scrollview in xml Layout of your activity.
Example:
XML code for your activity:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp"
android:fillViewport="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="200dp"
android:scaleType="centerCrop"
android:src="#drawable/image" />
<Button
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="KNOW MORE" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/title"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/description"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</ScrollView>
You can Use Scroll View With Linear Layout as well as With Relative layout.
You Can try this code, Just Copy and paste in XML File.
U'll Get Your ans :)
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:background="#android:color/black"
>
<TextView
android:id="#+id/TV_Welcome"
android:text="ADD YOUR VEHICLE"
android:layout_marginLeft="70dp"
android:layout_marginTop="10dp"
android:textSize="20dp"
android:layout_centerHorizontal="true"
android:textColor="#color/menu_color"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"/>
<RelativeLayout
android:id="#+id/RelativeLayout01"
android:layout_below="#+id/TV_Welcome"
android:layout_margin="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/TV_BlockNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Block No:"
android:textColor="#color/version_color"
android:layout_marginLeft="10dp"
android:textSize="15dp"
android:layout_alignParentLeft="true"
android:gravity="left"
/>
<Spinner
android:id="#+id/Spinner_BlockNo"
android:layout_marginLeft="30dp"
android:layout_toRightOf="#+id/TV_BlockNo"
android:background="#558cff"
android:layout_width="300dp"
android:layout_height="wrap_content">
</Spinner>
</RelativeLayout>
<RelativeLayout
android:id="#+id/RelativeLayout02"
android:layout_margin="10dp"
android:layout_below="#+id/RelativeLayout01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/TV_FlatNo"
android:text="Flat NO:"
android:textSize="15dp"
android:layout_marginLeft="10dp"
android:textColor="#color/version_color"
/>
<Spinner
android:id="#+id/Spinner_FlatNo"
android:layout_marginLeft="42dp"
android:layout_toRightOf="#+id/TV_FlatNo"
android:background="#558cff"
android:layout_width="300dp"
android:layout_height="wrap_content"></Spinner>
</RelativeLayout>
<RelativeLayout
android:id="#+id/RelativeLayout03"
android:layout_below="#+id/RelativeLayout02"
android:layout_margin="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/TV_VehicleNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Vehicle No:"
android:textColor="#color/version_color"
android:layout_marginLeft="10dp"
android:textSize="15dp"
android:layout_alignParentLeft="true"
android:gravity="left"
/>
<EditText
android:id="#+id/ET_VehicleNo"
android:layout_marginLeft="20dp"
android:hint="Enter Vehicle No"
android:textColorHint="#color/menu_glow"
android:textSize="20dp"
android:layout_toRightOf="#+id/TV_VehicleNo"
android:textColor="#558cff"
android:layout_width="400dp"
android:layout_height="wrap_content"
/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/RelativeLayout04"
android:layout_margin="10dp"
android:layout_below="#+id/RelativeLayout03"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/TV_VehicleType"
android:text="Vehicle Type:"
android:textSize="15dp"
android:layout_marginLeft="10dp"
android:textColor="#color/version_color"
/>
<Spinner
android:id="#+id/Spinner_VehicleType"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#+id/TV_VehicleType"
android:background="#558cff"
android:layout_width="300dp"
android:layout_height="wrap_content">
</Spinner>
</RelativeLayout>
<RelativeLayout
android:id="#+id/RelativeLayout05"
android:layout_margin="10dp"
android:layout_below="#id/RelativeLayout04"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/TV_OwnerName"
android:text="Owner Name:"
android:textSize="15dp"
android:textColor="#color/version_color"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:gravity="left">
</TextView>
<EditText
android:id="#+id/ET_OwnerName"
android:hint="Enter Owner Name"
android:textColorHint="#color/menu_glow"
android:inputType="textPersonName"
android:layout_marginLeft="20dp"
android:textSize="20dp"
android:layout_toRightOf="#id/TV_OwnerName"
android:textColor="#color/version_color"
android:layout_height="wrap_content"
android:layout_width="400dp">
</EditText>
</RelativeLayout>
<RelativeLayout
android:id="#+id/RelativeLayout06"
android:layout_margin="10dp"
android:layout_below="#id/RelativeLayout05"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/TV_MobileNo"
android:text="Mobile No:"
android:textSize="15dp"
android:textColor="#color/version_color"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:gravity="left">
</TextView>
<EditText
android:id="#+id/ET_MobileNo"
android:layout_marginLeft="40dp"
android:hint="Enter 10 digit"
android:textColorHint="#color/menu_glow"
android:inputType="phone"
android:textSize="20dp"
android:layout_toRightOf="#id/TV_MobileNo"
android:textColor="#color/version_color"
android:layout_height="wrap_content"
android:layout_width="200dp"
>
</EditText>
</RelativeLayout>
<RelativeLayout
android:id="#+id/RelativeLayout07"
android:layout_margin="10dp"
android:layout_below="#id/RelativeLayout06"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/TV_TelNo"
android:text="Telephone No:"
android:textSize="15dp"
android:textColor="#color/version_color"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
</TextView>
<EditText
android:id="#+id/ET_TelNo"
android:layout_marginLeft="20dp"
android:hint="Enter Telephone No"
android:textColorHint="#color/menu_glow"
android:inputType="number"
android:textSize="17dp"
android:layout_toRightOf="#id/TV_TelNo"
android:textColor="#color/version_color"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
</EditText>
</RelativeLayout>
<RelativeLayout
android:id="#+id/RelativeLayout08"
android:layout_margin="0dp"
android:layout_below="#id/RelativeLayout07"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/TV_Example"
android:text="(Example:0141-2206923)"
android:layout_marginLeft="120dp"
android:textSize="10dp"
android:textColor="#color/version_color"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
</TextView>
</RelativeLayout>
<ImageView
android:id="#+id/ImageView_Submit"
android:layout_marginTop="5dp"
android:layout_marginLeft="100dp"
android:layout_centerInParent="true"
android:layout_width="150dp"
android:layout_height="150dp"
android:src="#drawable/submit"
android:layout_below="#id/RelativeLayout08"
android:onClick="doSubmit"></ImageView>
</RelativeLayout>
</ScrollView>
You can make your activity scrollable using ScrollView.
Its very simple and effective to use.Just copy code of ScrollView from below and paste it in your layout xml file.
You can use this ScrollView with Linear as well as Relative Layout also.
Just need to remember one thing,ScrollView can have only one child widget.If you want more Children then wrap them into one container.
<?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">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/xyz.png"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView1"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<TextView
android:id="#+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView2"/>
<TextView
android:id="#+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView3"/>
<TextView
android:id="#+id/textView4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView4"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/btn_demo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Demo" />
</LinearLayout>
</LinearLayout>
</ScrollView>
I need to design the xml about below layout.
I try to use RelativeLayout to design, but I don't know
how to adjust the imageVivew3 in RelativeLayout.
Have anyone can teach me how to adjust the xml?
or have you nice xml design about this layout?
thank you very much.
my xml is below:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relative_bg"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView1"
android:layout_centerHorizontal="true"
android:visibility="visible"
android:layout_margin="0dp"/>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView2"
android:visibility="visible"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"/>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView3"
android:visibility="visible"
android:layout_centerVertical="true"
android:layout_below="#+id/imageView3"
android:layout_alignParentRight="true"
/>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView4"
android:layout_alignTop="#+id/textView1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="txt1"
android:id="#+id/textView1"
android:textColor="#color/white"
android:textSize="#dimen/common_size_large"
android:layout_below="#+id/imageView3"
android:layout_alignParentRight="true"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="txt2"
android:id="#+id/textView2"
android:textColor="#color/white"
android:layout_below="#+id/textView1"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
Try to LinearLayout instead of RelativeLayout..
And also use android:layout_weight atttribute ...code sample are given below... put this
code to your xml.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#android:color/white"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight=".75"
android:layout_marginTop="5dp"
>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="2"
android:layout_gravity="center"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/gerder"
android:textSize="12sp"
android:textStyle="bold"
android:contentDescription="#string/app_name"
android:layout_gravity="center"
android:paddingLeft="10dp"
android:gravity="center"
android:textColor="#android:color/black"
android:fontFamily="#string/providerFontFamily"
/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<RadioGroup
android:id="#+id/radioGender"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:layout_marginLeft="5dp"
>
<RadioButton
android:id="#+id/radioMale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/providerGenderMale"
android:checked="true" />
<RadioButton
android:id="#+id/radioFemale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/providerGenderFemale" />
</RadioGroup>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="2"
android:layout_gravity="center"
>
<TextView
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#string/providerFontFamily"
android:text="#string/age_range"
android:gravity="left"
android:textSize="12sp"
android:textStyle="bold"
android:textColor="#android:color/black"
android:layout_gravity="center"
/>
<Spinner
android:id="#+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:layout_marginRight="15dp"
android:prompt="#string/country_prompt"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>