How can I do the same view in different phone screens? - android

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 :)

Related

How to properly use linear layout in Android programming

I'm trying to create a layout that has a 4 categories on the page, and in each one 2 spinners with a title. However at the moment my layout is all over the place when i run an emulator. How can i fix this? i feel like i'm not understanding the concept of the layout properly since everything i add becomes rigid to the layout and i can't easily move things.
layout
<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"
tools:context=".Page1Fragment">
<TextView
android:id="#+id/TextView0"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginTop="25dp"
android:background="#A0DD0A"
android:text="TITLE" />
<LinearLayout
android:id="#+id/LinearLayoutTop"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#FFFFFF"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/LinearLayoutTopSub"
android:layout_width="match_parent"
android:layout_height="134dp"
android:layout_weight="1"
android:background="#FFFFFF"
android:orientation="horizontal">
<TextView
android:id="#+id/TextView1"
android:layout_width="81dp"
android:layout_height="20dp"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#FFFFFF"
android:text="Weight" />
<Spinner
android:id="#+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginTop="55dp"
android:layout_marginRight="25dp" />
<Spinner
android:id="#+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/spinner"
android:layout_marginLeft="0dp"
android:layout_marginTop="55dp"
android:layout_marginRight="25dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/LinearLayoutTopSub2"
android:layout_width="match_parent"
android:layout_height="134dp"
android:layout_weight="1"
android:background="#FFFFFF"
android:orientation="horizontal">
<TextView
android:id="#+id/TextView2"
android:layout_width="150dp"
android:layout_height="20dp"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#FFFFFF"
android:text="Computer" />
<Spinner
android:id="#+id/spinner2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginTop="55dp"
android:layout_marginRight="25dp" />
<Spinner
android:id="#+id/spinner3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/spinner2"
android:layout_marginLeft="0dp"
android:layout_marginTop="85dp"
android:layout_marginRight="30dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:background="#FFFFFF">
<LinearLayout
android:id="#+id/LinearLayoutTopSub3"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_weight="1"
android:background="#FFFFFF"
android:orientation="horizontal">
<TextView
android:id="#+id/TextView4"
android:layout_width="150dp"
android:layout_height="20dp"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#FFFFFF"
android:text="Distance" />
<Spinner
android:id="#+id/spinner4"
android:layout_width="75dp"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginTop="55dp"
android:layout_marginRight="25dp" />
<Spinner
android:id="#+id/spinner5"
android:layout_width="75dp"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginTop="55dp"
android:layout_marginRight="0dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/LinearLayoutTopSub4"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_weight="1"
android:background="#FFFFFF"
android:orientation="horizontal">
<TextView
android:id="#+id/TextView5"
android:layout_width="150dp"
android:layout_height="20dp"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#FFFFFF"
android:text="Other" />
<Spinner
android:id="#+id/spinner6"
android:layout_width="75dp"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginTop="55dp"
android:layout_marginRight="25dp" />
<Spinner
android:id="#+id/spinner7"
android:layout_width="75dp"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginTop="55dp"
android:layout_marginRight="0dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
I have added new linear and removed weight. try this one.
<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"
tools:context=".Page1Fragment">
<TextView
android:id="#+id/TextView0"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginTop="25dp"
android:background="#A0DD0A"
android:text="TITLE" />
<!-- adding new linear -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="#+id/LinearLayoutTop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/LinearLayoutTopSub"
android:layout_width="wrap_content"
android:layout_height="134dp"
android:background="#FFFFFF"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/TextView1"
android:layout_width="150dp"
android:layout_height="20dp"
android:layout_margin="10dp"
android:background="#FFFFFF"
android:text="Weight" />
<Spinner
android:id="#+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Spinner
android:id="#+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/LinearLayoutTopSub3"
android:layout_width="wrap_content"
android:layout_height="134dp"
android:background="#FFFFFF"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/TextView3"
android:layout_width="150dp"
android:layout_height="20dp"
android:layout_margin="10dp"
android:background="#FFFFFF"
android:text="Computer" />
<Spinner
android:id="#+id/spinner3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Spinner
android:id="#+id/spinner4"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/LinearLayoutBot"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/LinearLayoutBotSub"
android:layout_width="wrap_content"
android:layout_height="134dp"
android:background="#FFFFFF"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/TextView4"
android:layout_width="150dp"
android:layout_height="20dp"
android:layout_margin="10dp"
android:background="#FFFFFF"
android:text="Distance" />
<Spinner
android:id="#+id/spinner9"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Spinner
android:id="#+id/spinner7"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/LinearLayoutTopSub2"
android:layout_width="wrap_content"
android:layout_height="134dp"
android:background="#FFFFFF"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/TextView2"
android:layout_width="150dp"
android:layout_height="20dp"
android:layout_margin="10dp"
android:background="#FFFFFF"
android:text="Others" />
<Spinner
android:id="#+id/spinner2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Spinner
android:id="#+id/spinner5"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>

Two LinearLayouts side by side, one with minimum-width

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>

Scroll view is not scrolling smoothly when tab layout and viewpager is placed inside scroll view?

I am facing the issue in scroll view is not scrolling smoothly when the tab navigation is placed inside the scroll view .
The below code is the xml file in which the tab navigation is placed inside the scroll view. I don't know the reason why this issue is occurring.Please help me how to solve this.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/activity_interview_scam"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.zcodia.scamlookup.Activities.ScamDetailsActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="180dp"
android:foregroundGravity="center"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:id="#+id/profile_image"
android:background="#mipmap/bg_splash_cut"
android:src="#drawable/icon1"
/>
<TextView
android:text=""
android:textSize="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginBottom="8dp"
android:id="#+id/subCategoryTitle"
android:layout_above="#+id/textView11"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:textColor="#000000"/>
<TextView
android:text="Item ID:"
android:textSize="15dp"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView11"
android:layout_alignBottom="#+id/profile_image"
android:layout_marginLeft="15dp"
android:layout_marginBottom="13dp" />
<TextView
android:text=""
android:textSize="15dp"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/scamId"
android:layout_alignBottom="#+id/profile_image"
android:layout_marginLeft="75dp"
android:layout_marginBottom="13dp" />
<TextView
android:text="#string/arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_marginTop="19dp"
android:layout_marginLeft="10dp"
android:id="#+id/arrow_id"
android:textColor="#FFFFFF"
android:textSize="20dp"/>
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#FAFAFA"
android:focusableInTouchMode="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/linearLayout4"
android:layout_below="#+id/profile_image"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/relative_layout_1"
android:background="#FFFFFF">
<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="No Of Cases Reported"
android:layout_marginLeft="15dp"
android:textSize="14dp"
android:id="#+id/report_cases_id"
android:gravity="center"/>
<TextView
android:textSize="14dp"
android:textColor="#EF5350"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/scam_report_count"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:layout_marginTop="12dp"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FAFAFA">
<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="Report Loss"
android:textSize="14dp"
android:paddingLeft="15dp"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:id="#+id/report_loss_id"
android:gravity="center"
/>
<TextView
android:textSize="14dp"
android:textColor="#EF5350"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/loos_id"
android:layout_marginRight="10dp"
android:paddingTop="12dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="Possible Scammer Location"
android:textSize="14dp"
android:paddingLeft="15dp"
android:gravity="center"
android:id="#+id/possible_scammer_location_id" />
<TextView
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:textSize="14dp"
android:textColor="#EF5350"
android:paddingTop="12dp"
android:layout_marginRight="10dp"
android:id="#+id/scam_location"
android:ellipsize="end"/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#FAFAFA"
android:orientation="horizontal"
>
<TextView
android:layout_width="0dp"
android:layout_height="40dp"
android:text="Target Medium"
android:textSize="14dp"
android:paddingTop="10dp"
android:layout_weight="1"
android:layout_marginLeft="10dp"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_marginRight="0dp"
android:id="#+id/scam_medium_linear">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/scam_medium_icon"
android:textSize="20dp"
android:layout_gravity="center"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:layout_marginTop="3dp"
android:textColor="#EF5350"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:id="#+id/scam_medium_text"
android:textColor="#EF5350"
android:layout_marginTop="10dp"
android:layout_marginLeft="0dp"
android:layout_alignParentRight="true"
android:textSize="14dp"
android:gravity="center"
android:layout_marginRight="10dp"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:text="Tactic"
android:layout_marginLeft="15dp"
android:textSize="14dp"
android:gravity="center"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tactic_linear_layout"
android:background="#drawable/margin_color"
android:orientation="horizontal"
android:layout_marginLeft="20dp"
android:layout_marginTop="0dp"
android:paddingBottom="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/add_new_tactics"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/rectangele_width"
>
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/tab_layout"
app:tabMode="fixed"
app:tabTextColor="#ccc"
app:tabPaddingStart="12dp"
app:tabSelectedTextColor="#D32F2F"
app:tabIndicatorColor="#D32F2F"
app:tabGravity="fill"
></android.support.design.widget.TabLayout>
</android.support.design.widget.AppBarLayout>
</LinearLayout>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="420dp"
android:id="#+id/viewPager2"
android:background="#FAFAFA">
</android.support.v4.view.ViewPager>
</LinearLayout>
</ScrollView>
</LinearLayout>
Replace android.support.v4.widget.NestedScrollView instead of scroll view. It works for me try this....

Adjust layout to fit for every content Android

I have some customized shape for one layout background, but some content is mixed up depends on what content i open.
I will show you now three images:
1.
2.
3.
How could i simplify this layout and if you can see, the layout size changes depends on size of text and if there is image in it.
This is how my layout looks:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:id="#+id/parent_container"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/bg_dialog"
android:fillViewport="false">
<RelativeLayout
android:id="#+id/background"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/bg_status"
android:gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="15dp"
android:orientation="vertical"
android:paddingTop="#dimen/feed_item_padding_top_bottom">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="#dimen/feed_item_padding_left_right"
android:paddingRight="#dimen/feed_item_padding_left_right">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/profilePic"
android:layout_width="#dimen/feed_item_profile_pic"
android:layout_height="#dimen/feed_item_profile_pic"
android:src="#drawable/user_profile_image"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="#dimen/feed_item_profile_info_padd"
android:paddingStart="#dimen/feed_item_profile_info_padd">
<TextView
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#android:color/black"
android:textSize="#dimen/feed_item_profile_name"
android:textStyle="bold"/>
<TextView
android:id="#+id/timestamp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/timestamp"
android:textSize="#dimen/feed_item_timestamp"/>
</LinearLayout>
</LinearLayout>
<TextView
android:id="#+id/txtStatusMsg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:paddingLeft="#dimen/feed_item_status_pad_left_right"
android:paddingRight="#dimen/feed_item_status_pad_left_right"
android:paddingTop="#dimen/feed_item_status_pad_top"
android:textColor="#android:color/black"/>
<ImageView
android:id="#+id/feedImage1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#android:color/white"
android:visibility="visible"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp">
<CheckBox
android:id="#+id/btn_like"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#null"
android:button="#drawable/like_button_state"
android:padding="10dp"
android:text="#string/btn_like_text"
android:textColor="#android:color/black"/>
<TextView
android:id="#+id/tv_like"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="0"
android:textColor="#android:color/black"
android:textSize="18sp"/>
<Button
android:id="#+id/btn_comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#null"
android:drawableLeft="#drawable/ic_comment"
android:drawableStart="#drawable/ic_comment"
android:padding="10dp"
android:text="#string/btn_comment_text"
android:textColor="#android:color/black"/>
<TextView
android:id="#+id/tv_comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="0"
android:textColor="#android:color/black"
android:textSize="18sp"/>
<ImageButton
android:id="#+id/btn_share"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#null"
android:gravity="center"
android:padding="10dp"
android:src="#drawable/ic_action_share"/>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
<Button
android:id="#+id/btn_report"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#null"
android:gravity="center"
android:text="REPORT"
android:textColor="#android:color/black"/>
<TextView
android:id="#+id/tv_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/btn_report"
android:layout_alignParentTop="true"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:layout_toLeftOf="#+id/tv_category"
android:layout_toStartOf="#+id/tv_category"
android:gravity="center"
android:text="Category:"
android:textColor="#android:color/black"/>
<TextView
android:id="#+id/tv_category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/tv_info"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:gravity="center"
android:text="#Good Night"
android:textColor="#android:color/holo_red_dark"/>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</ScrollView>

margin-botton doesnt work in layout android

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"/>

Categories

Resources