Using layout_weight changes the textview size - android

I have two TextViews which I want to be centered (in the middle) and they should have a fix Size of about 30 dp, how can I achieve that?
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_weight="0.5"
android:padding="7dp"
android:textSize="30sp"
android:layout_marginRight="20dp"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:text="N"
android:background="#color/black"
android:textColor="#color/white"
android:id="#+id/textView1" android:gravity="center" />
<TextView
android:layout_weight="0.5"
android:padding="7dp"
android:textSize="30sp"
android:layout_marginRight="20dp"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:text="N"
android:background="#color/black"
android:textColor="#color/white"
android:id="#+id/textView2" android:gravity="center"/>

If I understand you correctly you want to use
android:gravity="center"
in your LinearLayout
Something similar to this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<TextView
android:padding="7dp"
android:textSize="30sp"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:text="N"
android:background="#color/black"
android:textColor="#color/white"
android:id="#+id/textView1" android:gravity="center"
android:layout_marginRight="10dp" />
<TextView
android:padding="7dp"
android:textSize="30sp"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:text="N"
android:background="#color/black"
android:textColor="#color/white"
android:id="#+id/textView2" android:gravity="center"
android:layout_marginLeft="10dp" />

Try this!!!!
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:layout_weight="0.5"
android:padding="7dp"
android:textSize="30sp"
android:layout_marginRight="20dp"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:text="N"
android:background="#color/black"
android:textColor="#color/white"
android:id="#+id/textView1" />
<TextView
android:layout_weight="0.5"
android:padding="7dp"
android:textSize="30sp"
android:layout_marginRight="20dp"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:text="N"
android:background="#color/black"
android:textColor="#color/white"
android:id="#+id/textView2" />

Related

Stop text view from going out of screen

Im trying to make an app in android studio. I have a textview with a circular background. The thing is that when i install it on ta physical device the Text view goes of the screen.
Hers the preview in android studio:
The Xml code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="55dp"
android:orientation="horizontal"
android:background="#drawable/top_bar">
<TextView
android:id="#+id/textView3"
android:layout_width="40dp"
android:layout_height="match_parent"
android:layout_weight="0"
android:drawableLeft="#drawable/ic_keyboard_arrow_left_black_24dp"
/>
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:fontFamily="#font/segoeui"
android:gravity="center_vertical|start"
android:text="App name and image"
android:textColor="#FFFFFF"
android:textSize="30dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:orientation="vertical">
<TextView
android:id="#+id/textView6"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="#font/segoeui"
android:gravity="center"
android:text="Pakistan vs Australia T20"
android:textColor="#ffff"
android:textSize="24dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1.5dp"
android:background="#ffff"
android:orientation="vertical"
android:layout_marginLeft="47dp"
android:layout_marginRight="47dp"></LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="300dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="247dp"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fontFamily="#font/segoeui"
android:gravity="center"
android:text="Match Odds"
android:textColor="#ffff"
android:textSize="17dp" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fontFamily="#font/segoeui"
android:paddingLeft="10dp"
android:text="Favourite"
android:textColor="#ffff"
android:textSize="17dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="30dp"
android:orientation="horizontal">
<TextView
android:id="#+id/textView12"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="0"
android:textColor="#ffff"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:id="#+id/textView11"
android:layout_width="20dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="-"
android:textColor="#ffff"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:id="#+id/textView10"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="0"
android:textColor="#ffff"
android:textSize="20dp"
android:textStyle="bold" />
</LinearLayout>
<TextView
android:id="#+id/textView13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginTop="30dp"
android:fontFamily="#font/segoeui"
android:gravity="center"
android:text="WestIndies"
android:textColor="#ffff"
android:textSize="16dp"
android:visibility="visible" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal">
<TextView
android:id="#+id/textView4"
android:layout_width="100dp"
android:layout_height="1dp"
android:layout_marginLeft="6dp"
android:background="#color/margins"
android:text="TextView" />
<TextView
android:id="#+id/textView7"
android:layout_width="100dp"
android:layout_height="1dp"
android:layout_marginLeft="30dp"
android:background="#color/margins"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:id="#+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fontFamily="#font/segoeui"
android:gravity="center"
android:text="Session"
android:textColor="#ffff"
android:textSize="17dp" />
<TextView
android:id="#+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fontFamily="#font/segoeui"
android:gravity="center"
android:text="Runs/Balls"
android:textColor="#ffff"
android:textSize="17dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:orientation="horizontal">
<TextView
android:id="#+id/textView17"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="0"
android:textColor="#FF0000"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:id="#+id/textView18"
android:layout_width="20dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="-"
android:textColor="#ffff"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:id="#+id/textView19"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="0"
android:textColor="#ffff"
android:textSize="20dp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="0dp"
android:orientation="vertical"
>
<TextView
android:id="#+id/TextViewID"
android:layout_width="110dp"
android:layout_height="110dp"
android:layout_marginTop="80dp"
android:layout_marginLeft="35dp"
android:background="#drawable/green_circle"
android:gravity="center"
android:text="2"
android:textColor="#ff2800"
android:textSize="13sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
What im getting on the screen:
ive tried using different devices with different screen sizes but all give the same result. How can i solve this.
TIA..!!!
I think it's because the LinearLayout where that round TextView is, is actually a child of another LinearLayout with horizontal orientation, and you have another empty LinearLayout of width 250dp right before it, which pushes the relevant layout out of screen. Can you try removing the empty LinearLayout and see if it helps?

ScrollView between two Layouts in ConstraintLayout

I want to put a scrollView between two Layout and put all 3 layout in 1 constraintLayout as below :
<ConstraintLayout>
<LinearLayout> // Title
<ScrollView>
<RelativeLayout> // Buttons
<ConstraintLayout>
this in my Layout XML code :
<android.support.constraint.ConstraintLayout
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/registerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical"
app:layout_constraintRight_toRightOf="parent"
tools:context="momtaz.moshaver_yar.StudentFragment_Register">
<LinearLayout
android:id="#+id/titleLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#color/colorPrimary"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/registerStudentTitleTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="ثبت نام دانش آموز"
android:textColor="#color/colorPrimaryText"
android:textSize="20sp" />
</LinearLayout>
<ScrollView
android:id="#+id/registerStudentScroll"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#android:color/white"
android:fillViewport="true"
android:orientation="vertical"
android:scrollbars="vertical"
app:layout_constraintBottom_toTopOf="#+id/registerStudentBtn"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/titleLayout">
<LinearLayout
android:id="#+id/regstscrollayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layoutDirection="rtl"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/registerNameLabel"
android:layout_width="125dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:gravity="left"
android:labelFor="#id/regStNameEdit"
android:text="نام و نام خانوادگی :"
android:textColor="#android:color/black"
android:textSize="15sp" />
<EditText
android:id="#+id/regStNameEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/editselector"
android:gravity="right|center_vertical"
android:padding="3dp"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/registerBirthDateLabel"
android:layout_width="125dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:gravity="left"
android:text="تاریخ تولد :"
android:textColor="#android:color/black"
android:textSize="15sp" />
<TextView
android:id="#+id/registerBirthDateTxt"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:gravity="center"
android:textColor="#android:color/black"
android:textDirection="rtl"
android:textSize="14sp"
tools:text="10/08/1369" />
<Button
android:id="#+id/registerBirthDateBtn"
android:layout_width="28dp"
android:layout_height="28dp"
android:background="#drawable/datebtnselector" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/registerGenderLabel"
android:layout_width="125dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:gravity="left"
android:text="جنسیت :"
android:textColor="#android:color/black"
android:textSize="15sp" />
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="#+id/registerGenderBoy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="#drawable/radiobtnselector"
android:paddingLeft="5dp"
android:text=" پسر"
android:textColor="#android:color/black"
android:textSize="16sp" />
<RadioButton
android:id="#+id/registerGenderGirl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="#drawable/radiobtnselector"
android:text=" دختر"
android:textColor="#android:color/black"
android:textSize="16sp" />
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/registerMCodeLabel"
android:layout_width="125dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:gravity="left"
android:text="کد ملی :"
android:textColor="#android:color/black"
android:textSize="15sp" />
<EditText
android:id="#+id/regStMCodeEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/editselector"
android:gravity="left|center_vertical"
android:inputType="number"
android:padding="3dp"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/registerMobileLabel"
android:layout_width="125dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:gravity="left"
android:labelFor="#+id/regStPhoneEdit"
android:text="شماره تماس :"
android:textColor="#android:color/black"
android:textSize="15sp" />
<EditText
android:id="#+id/regStMobileEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/editselector"
android:gravity="left|center_vertical"
android:inputType="phone"
android:padding="3dp"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/registerPhoneLabel"
android:layout_width="125dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:gravity="left"
android:text="شماره تماس منزل :"
android:textColor="#android:color/black"
android:textSize="15sp" />
<EditText
android:id="#+id/regStPhoneEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/editselector"
android:gravity="left|center_vertical"
android:inputType="phone"
android:padding="3dp"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/registerStGradeLabel"
android:layout_width="125dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:gravity="left"
android:text="پایه تحصیلی :"
android:textColor="#android:color/black"
android:textSize="15sp" />
<EditText
android:id="#+id/regStGradeEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/editselector"
android:gravity="left|center_vertical"
android:inputType="phone"
android:padding="3dp"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TableRow
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_margin="10dp"
android:background="#android:color/darker_gray" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/registerAdviserLabel"
android:layout_width="125dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:gravity="left"
android:labelFor="#id/regStAdviserEdit"
android:text="کد مشاور :"
android:textColor="#android:color/black"
android:textSize="15sp" />
<AutoCompleteTextView
android:id="#+id/regStAdviserEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/editselector"
android:gravity="left|center_vertical"
android:inputType="number"
android:padding="3dp"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/registerAdviserNameLabel"
android:layout_width="125dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:gravity="left"
android:labelFor="#id/regStNameEdit"
android:text="نام مشاور :"
android:textColor="#android:color/black"
android:textSize="15sp" />
<TextView
android:id="#+id/regStAdviserNameTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#android:color/black"
android:textSize="15sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TableRow
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_margin="10dp"
android:background="#android:color/darker_gray" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/registerStUNameLabel"
android:layout_width="125dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:gravity="left"
android:labelFor="#id/regStUNameEdit"
android:text="نام کاربری :"
android:textColor="#android:color/black"
android:textSize="15sp" />
<EditText
android:id="#+id/regStUNameEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/editselector"
android:gravity="left|center_vertical"
android:inputType="number"
android:padding="3dp"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/registerStUPassLabel"
android:layout_width="125dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:gravity="left"
android:labelFor="#id/regStUPassEdit"
android:text="رمز عبور :"
android:textColor="#android:color/black"
android:textSize="15sp" />
<EditText
android:id="#+id/regStUPassEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/editselector"
android:gravity="left|center_vertical"
android:inputType="number"
android:padding="3dp"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/registerStUPass2Label"
android:layout_width="125dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:gravity="left"
android:labelFor="#id/regStUPass2Edit"
android:text="تکرار رمز عبور :"
android:textColor="#android:color/black"
android:textSize="15sp" />
<EditText
android:id="#+id/regStUPass2Edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/editselector"
android:gravity="left|center_vertical"
android:inputType="number"
android:padding="3dp"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<RelativeLayout
android:id="#+id/registerStudentBtn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<Button
android:id="#+id/regStPostBtn"
android:layout_width="80dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_marginLeft="5dp"
android:background="#drawable/btnselector"
android:text="ثبت"
android:textColor="#android:color/white"
android:textSize="16sp" />
<ImageView
android:id="#+id/regStProgressImg"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_toLeftOf="#+id/regStPostBtn"
android:background="#drawable/loading_animate" />
<Button
android:id="#+id/regStCancelBtn"
android:layout_width="80dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:background="#drawable/btnselector"
android:text="انصراف"
android:textColor="#android:color/white"
android:textSize="16sp" />
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
I have created this connections of constraintLayout :
Top of TitleLayout to Top of Parent
Top of ScrollView to Bottom of TitleLayout
Bottom of ScrollView to Top of ButtonLayout
Bottom of ButtonLayout to Bottom of Parent
Right and Left of All Layouts to Right and Left of Parent
There is no problem is Design-View but when I test it in GenyMotion emulator, the ButtonLayout doesn't show, it seems that the Height of ScrollView is larger than the space between bottom of TitleView and top of ButtonLayout, I can't find out whats going wrong !
I have tested NestedScrollView instead of ScrollView or RelativeLayout instead of ConstraintLayout but the problem not solved
I suggest you put the LinearLayout, ScrollView and the RelativeLayout in a vertical chain to keep them properly constrained to each other and to prevent them from overlapping. In order to create the chain you need to add a couple additional constraints:
bottom of TitleLayout to top of ScrollView
top of ButtonLayout to bottom of ScrollView
Please note that I only added two additional constraints to create a chain and did not change anything else or did not fix any other small problems with the XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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/registerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical"
app:layout_constraintRight_toRightOf="parent"
tools:context="momtaz.moshaver_yar.StudentFragment_Register">
<LinearLayout
android:id="#+id/titleLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#color/colorPrimary"
android:orientation="vertical"
app:layout_constraintBottom_toTopOf="#id/registerStudentScroll"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/registerStudentTitleTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="ثبت نام دانش آموز"
android:textColor="#color/colorPrimaryText"
android:textSize="20sp" />
</LinearLayout>
<ScrollView
android:id="#+id/registerStudentScroll"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#android:color/white"
android:fillViewport="true"
android:orientation="vertical"
android:scrollbars="vertical"
app:layout_constraintBottom_toTopOf="#+id/registerStudentBtn"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/titleLayout">
<LinearLayout
android:id="#+id/regstscrollayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layoutDirection="rtl"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/registerNameLabel"
android:layout_width="125dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:gravity="left"
android:labelFor="#id/regStNameEdit"
android:text="نام و نام خانوادگی :"
android:textColor="#android:color/black"
android:textSize="15sp" />
<EditText
android:id="#+id/regStNameEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/editselector"
android:gravity="right|center_vertical"
android:padding="3dp"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/registerBirthDateLabel"
android:layout_width="125dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:gravity="left"
android:text="تاریخ تولد :"
android:textColor="#android:color/black"
android:textSize="15sp" />
<TextView
android:id="#+id/registerBirthDateTxt"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:gravity="center"
android:textColor="#android:color/black"
android:textDirection="rtl"
android:textSize="14sp"
tools:text="10/08/1369" />
<Button
android:id="#+id/registerBirthDateBtn"
android:layout_width="28dp"
android:layout_height="28dp"
android:background="#drawable/datebtnselector" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/registerGenderLabel"
android:layout_width="125dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:gravity="left"
android:text="جنسیت :"
android:textColor="#android:color/black"
android:textSize="15sp" />
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="#+id/registerGenderBoy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="#drawable/radiobtnselector"
android:paddingLeft="5dp"
android:text=" پسر"
android:textColor="#android:color/black"
android:textSize="16sp" />
<RadioButton
android:id="#+id/registerGenderGirl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="#drawable/radiobtnselector"
android:text=" دختر"
android:textColor="#android:color/black"
android:textSize="16sp" />
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/registerMCodeLabel"
android:layout_width="125dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:gravity="left"
android:text="کد ملی :"
android:textColor="#android:color/black"
android:textSize="15sp" />
<EditText
android:id="#+id/regStMCodeEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/editselector"
android:gravity="left|center_vertical"
android:inputType="number"
android:padding="3dp"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/registerMobileLabel"
android:layout_width="125dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:gravity="left"
android:labelFor="#+id/regStPhoneEdit"
android:text="شماره تماس :"
android:textColor="#android:color/black"
android:textSize="15sp" />
<EditText
android:id="#+id/regStMobileEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/editselector"
android:gravity="left|center_vertical"
android:inputType="phone"
android:padding="3dp"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/registerPhoneLabel"
android:layout_width="125dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:gravity="left"
android:text="شماره تماس منزل :"
android:textColor="#android:color/black"
android:textSize="15sp" />
<EditText
android:id="#+id/regStPhoneEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/editselector"
android:gravity="left|center_vertical"
android:inputType="phone"
android:padding="3dp"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/registerStGradeLabel"
android:layout_width="125dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:gravity="left"
android:text="پایه تحصیلی :"
android:textColor="#android:color/black"
android:textSize="15sp" />
<EditText
android:id="#+id/regStGradeEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/editselector"
android:gravity="left|center_vertical"
android:inputType="phone"
android:padding="3dp"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TableRow
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_margin="10dp"
android:background="#android:color/darker_gray" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/registerAdviserLabel"
android:layout_width="125dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:gravity="left"
android:labelFor="#id/regStAdviserEdit"
android:text="کد مشاور :"
android:textColor="#android:color/black"
android:textSize="15sp" />
<AutoCompleteTextView
android:id="#+id/regStAdviserEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/editselector"
android:gravity="left|center_vertical"
android:inputType="number"
android:padding="3dp"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/registerAdviserNameLabel"
android:layout_width="125dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:gravity="left"
android:labelFor="#id/regStNameEdit"
android:text="نام مشاور :"
android:textColor="#android:color/black"
android:textSize="15sp" />
<TextView
android:id="#+id/regStAdviserNameTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#android:color/black"
android:textSize="15sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TableRow
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_margin="10dp"
android:background="#android:color/darker_gray" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/registerStUNameLabel"
android:layout_width="125dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:gravity="left"
android:labelFor="#id/regStUNameEdit"
android:text="نام کاربری :"
android:textColor="#android:color/black"
android:textSize="15sp" />
<EditText
android:id="#+id/regStUNameEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/editselector"
android:gravity="left|center_vertical"
android:inputType="number"
android:padding="3dp"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/registerStUPassLabel"
android:layout_width="125dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:gravity="left"
android:labelFor="#id/regStUPassEdit"
android:text="رمز عبور :"
android:textColor="#android:color/black"
android:textSize="15sp" />
<EditText
android:id="#+id/regStUPassEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/editselector"
android:gravity="left|center_vertical"
android:inputType="number"
android:padding="3dp"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/registerStUPass2Label"
android:layout_width="125dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:gravity="left"
android:labelFor="#id/regStUPass2Edit"
android:text="تکرار رمز عبور :"
android:textColor="#android:color/black"
android:textSize="15sp" />
<EditText
android:id="#+id/regStUPass2Edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/editselector"
android:gravity="left|center_vertical"
android:inputType="number"
android:padding="3dp"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<RelativeLayout
android:id="#+id/registerStudentBtn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="#id/registerStudentScroll"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<Button
android:id="#+id/regStPostBtn"
android:layout_width="80dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_marginLeft="5dp"
android:background="#drawable/btnselector"
android:text="ثبت"
android:textColor="#android:color/white"
android:textSize="16sp" />
<ImageView
android:id="#+id/regStProgressImg"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_toLeftOf="#+id/regStPostBtn"
android:background="#drawable/loading_animate" />
<Button
android:id="#+id/regStCancelBtn"
android:layout_width="80dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:background="#drawable/btnselector"
android:text="انصراف"
android:textColor="#android:color/white"
android:textSize="16sp" />
</RelativeLayout>
</android.support.constraint.ConstraintLayout>

listview is not displaying in android API 16 version.but not dispalying under versions.how can i fix this?

This is xml code of my layout.its not displaying in API16 but its working properly in API
23,but its not working under versions.notging to display.
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:dividerHeight="10dp"
android:id="#+id/list_primary">
</ListView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/text14"
android:text="Taken"
android:textColor="#color/black"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:textSize="20sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/text16"
android:text="Skip"
android:textColor="#color/black"
android:layout_marginTop="-25dp"
android:layout_gravity="center"
android:textSize="20sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dismiss"
android:id="#+id/text15"
android:textColor="#color/black"
android:layout_gravity="right"
android:layout_marginTop="-25dp"
android:layout_marginRight="20dp"
android:textSize="20sp"
/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="match_parent">
<Button
android:layout_width="70dp"
android:layout_height="70dp"
android:background="#mipmap/btn1"
android:layout_marginLeft="15dp"
android:id="#+id/btn_taken" />
<Button
android:layout_width="70dp"
android:layout_height="70dp"
android:background="#mipmap/btn2"
android:id="#+id/btnskip"
android:layout_gravity="center"
android:layout_marginTop="-70dp"
/>
<Button
android:layout_width="70dp"
android:layout_height="70dp"
android:background="#mipmap/btn3"
android:id="#+id/btndismiss"
android:layout_marginRight="20dp"
android:layout_gravity="right"
android:layout_marginTop="-70dp"
/>
</LinearLayout>
list_view.xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="120dp"
android:orientation="vertical"
android:elevation="5dp"
android:background="#drawable/listview">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="1dp"
android:orientation="horizontal"
android:background="#drawable/logback">
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:id="#+id/label_medname"
android:layout_marginTop="10dp"
android:layout_marginLeft="15dp"
android:text="Medicine Name"
android:textColor="#000"
android:textSize="15dp"/>
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:id="#+id/text_mediname"
android:layout_marginTop="10dp"
android:layout_marginLeft="15dp"
android:text="Name"
android:textColor="#000"
android:textSize="15dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="5dp"
android:background="#drawable/logback">
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:id="#+id/label_quan"
android:layout_marginTop="10dp"
android:text="Quantity :"
android:layout_marginLeft="15dp"
android:textColor="#000"
android:textSize="15dp"/>
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:id="#+id/text_quantity"
android:layout_marginTop="10dp"
android:text="Quantity"
android:layout_marginLeft="15dp"
android:textColor="#000"
android:textSize="15dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="5dp"
android:background="#drawable/logback">
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:id="#+id/label_when"
android:layout_marginTop="10dp"
android:layout_alignParentRight="true"
android:layout_marginLeft="15dp"
android:text="When :"
android:textColor="#000"
android:textSize="15dp"/>
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:id="#+id/text_when"
android:layout_marginTop="10dp"
android:layout_alignParentRight="true"
android:layout_marginLeft="15dp"
android:text="When"
android:textColor="#000"
android:textSize="15dp"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
how can i fix this?
every thing is exactly same but data is not displaying in the list. Please i'm badly stuck here and i really need some fast help. Waiting for some positive response !

Relative Layout alignment

I have used Relative layout with some views. I need to align the views in horizontally, but the views are not displaying same in all the screen size devices?
<RelativeLayout
android:id="#+id/layout_relative"
android:layout_width="fill_parent"
android:layout_height="90dp"
android:layout_marginTop="-5dp"
android:background="#007DD7">
<TextView
android:id="#+id/text1_login"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginLeft="45dp"
android:layout_marginTop="10dp"
android:background="#drawable/circle"
android:backgroundTint="#color/white"
android:gravity="center"
android:shadowRadius="10.0"
android:text="1"
android:textColor="#android:color/holo_blue_dark"
android:textSize="18sp" />
<TextView
android:id="#+id/text2_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/text1_login"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="45dp"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:text="Login"
android:textColor="#color/white"
android:textSize="20sp" />
<View
android:id="#+id/1_line"
android:layout_centerHorizontal="#+id/text1_login"
android:layout_width="70dp"
android:layout_height="2dp"
android:layout_marginLeft="90dp"
android:layout_marginTop="30dp"
android:background="#android:color/white"
android:backgroundTint="#color/add_contact_selected"/>
<TextView
android:id="#+id/text1_delivery"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginLeft="170dp"
android:layout_marginTop="10dp"
android:background="#drawable/circle"
android:shadowRadius="10.0"
android:text="2"
android:gravity="center"
android:textColor="#android:color/holo_blue_dark"
android:textSize="18sp"
android:backgroundTint="#color/add_contact_selected"/>
<TextView
android:id="#+id/text2_delivery"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/text1_delivery"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="25dp"
android:gravity="center_horizontal"
android:maxLines="2"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:text="Delivery"
android:textColor="#color/add_contact_selected"
android:textSize="20sp" />
<View
android:id="#+id/2_line"
android:layout_centerHorizontal="#+id/text1_delivery"
android:layout_width="80dp"
android:layout_height="2dp"
android:layout_marginLeft="215dp"
android:layout_marginTop="30dp"
android:background="#android:color/white"
android:backgroundTint="#color/add_contact_selected"/>
<TextView
android:id="#+id/text1_payment"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginLeft="300dp"
android:layout_marginTop="10dp"
android:background="#drawable/circle"
android:gravity="center"
android:shadowRadius="10.0"
android:text="3"
android:textColor="#android:color/holo_blue_dark"
android:textSize="18sp"
android:backgroundTint="#color/add_contact_selected"/>
<TextView
android:id="#+id/text2_payment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/text1_payment"
android:gravity="center_horizontal"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="260dp"
android:maxLines="2"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:text="Payment"
android:textColor="#color/add_contact_selected"
android:textSize="20sp"
/>
</RelativeLayout>
You need to use LinearLayout with android:orientation="horizontal" and play with android:layout_weight to allign your views.
I've edited your code:
<LinearLayout
android:id="#+id/layout_linear"
android:layout_width="fill_parent"
android:layout_height="90dp"
android:layout_marginTop="-5dp"
android:background="#007DD7"
android:orientation="horizontal">
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center">
<TextView
android:id="#+id/text1_login"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:background="#drawable/circle"
android:backgroundTint="#color/white"
android:gravity="center"
android:shadowRadius="10.0"
android:text="1"
android:textColor="#android:color/holo_blue_dark"
android:textSize="18sp" />
<TextView
android:id="#+id/text2_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/text1_login"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:text="Login"
android:textColor="#color/white"
android:textSize="20sp" />
<View
android:id="#+id/1_line"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#android:color/white"
android:backgroundTint="#color/add_contact_selected"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center">
<TextView
android:id="#+id/text1_delivery"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:background="#drawable/circle"
android:shadowRadius="10.0"
android:text="2"
android:gravity="center"
android:textColor="#android:color/holo_blue_dark"
android:textSize="18sp"
android:backgroundTint="#color/add_contact_selected"/>
<TextView
android:id="#+id/text2_delivery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/text1_delivery"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:gravity="center_horizontal"
android:maxLines="2"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:text="Delivery"
android:textColor="#color/add_contact_selected"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center">
<TextView
android:id="#+id/text1_payment"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:background="#drawable/circle"
android:gravity="center"
android:shadowRadius="10.0"
android:text="3"
android:textColor="#android:color/holo_blue_dark"
android:textSize="18sp"
android:backgroundTint="#color/add_contact_selected"/>
<TextView
android:id="#+id/text2_payment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/text1_payment"
android:gravity="center_horizontal"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:maxLines="2"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:text="Payment"
android:textColor="#color/add_contact_selected"
android:textSize="20sp"
/>
</LinearLayout>
</LinearLayout>
Update: add the horizontal line between circles:
<RelativeLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:id="#+id/text1_login"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:background="#drawable/circle"
android:backgroundTint="#color/white"
android:gravity="center"
android:shadowRadius="10.0"
android:text="1"
android:textColor="#android:color/holo_blue_dark"
android:textSize="18sp"
android:layout_centerHorizontal="true" />
<TextView
android:id="#+id/text2_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/text1_login"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:text="Login"
android:textColor="#color/white"
android:textSize="20sp"
android:layout_centerHorizontal="true" />
<View
android:id="#+id/1_line"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#android:color/white"
android:backgroundTint="#color/add_contact_selected"
android:layout_marginTop="30dp"
android:layout_toRightOf="#+id/text1_login" />
</RelativeLayout>
<RelativeLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<View
android:id="#+id/2_line"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#android:color/white"
android:backgroundTint="#color/add_contact_selected"
android:layout_marginTop="30dp"
android:layout_toLeftOf="#+id/text1_delivery" />
<TextView
android:id="#+id/text1_delivery"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:background="#drawable/circle"
android:shadowRadius="10.0"
android:text="2"
android:textColor="#android:color/holo_blue_dark"
android:textSize="18sp"
android:backgroundTint="#color/add_contact_selected"
android:gravity="center"
android:layout_centerHorizontal="true" />
<View
android:id="#+id/22_line"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#android:color/white"
android:backgroundTint="#color/add_contact_selected"
android:layout_marginTop="30dp"
android:layout_toRightOf="#+id/text1_delivery" />
<TextView
android:id="#+id/text2_delivery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/text1_delivery"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:gravity="center_horizontal"
android:maxLines="2"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:text="Delivery"
android:textColor="#color/add_contact_selected"
android:textSize="20sp"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<RelativeLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<View
android:id="#+id/3_line"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#android:color/white"
android:backgroundTint="#color/add_contact_selected"
android:layout_marginTop="30dp"
android:layout_toLeftOf="#+id/text1_payment" />
<TextView
android:id="#+id/text1_payment"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:background="#drawable/circle"
android:gravity="center"
android:shadowRadius="10.0"
android:text="3"
android:textColor="#android:color/holo_blue_dark"
android:textSize="18sp"
android:backgroundTint="#color/add_contact_selected"
android:layout_centerHorizontal="true" />
<TextView
android:id="#+id/text2_payment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/text1_payment"
android:gravity="center_horizontal"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:maxLines="2"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:text="Payment"
android:textColor="#color/add_contact_selected"
android:textSize="20sp"
android:layout_centerHorizontal="true" />
</RelativeLayout>
To align views horizontally , you should use Linear Layout with horizontal orientation and assign weights to each child views.
Check this example which i have written using your layout -
<LinearLayout
android:id="#+id/layout_relative"
android:layout_width="fill_parent"
android:layout_height="90dp"
android:layout_marginTop="-5dp"
android:orientation="horizontal"
android:background="#007DD7">
<TextView
android:id="#+id/text1_login"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginLeft="45dp"
android:layout_marginTop="10dp"
android:background="#drawable/circle"
android:backgroundTint="#color/white"
android:gravity="center"
android:shadowRadius="10.0"
android:text="1"
android:layout_weight="1"
android:textColor="#android:color/holo_blue_dark"
android:textSize="18sp" />
<TextView
android:id="#+id/text2_login"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="45dp"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:text="Login"
android:textColor="#color/white"
android:textSize="20sp" />
<TextView
android:id="#+id/text1_delivery"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="1"
android:layout_gravity="center"
android:layout_marginLeft="170dp"
android:layout_marginTop="10dp"
android:background="#drawable/circle"
android:shadowRadius="10.0"
android:text="2"
android:gravity="center"
android:textColor="#android:color/holo_blue_dark"
android:textSize="18sp"
android:backgroundTint="#color/add_contact_selected"/>
</LinearLayout>
I saw all the answers people who has suggest to use LinearLayout.One thing you have to know very clearly.By using the Relative or Linear we can achieve all the layout design.
First you have to analyse which design will be good.Implementation may be depends on three things.
1.Easy designing
2.Layout performance
3.How much you know about attributes of layout.
My suggestion also Linear only for your implementation but some times multiple inner linear layout will cause performance issue and this also you should aware of it.
How we are developing the code is not important,how we are optimizing the code is very important.

I am getting weightsum error thaugh i changed from layout_weightsum to weightsum

I am keeping 9 images in a 3 rows like a 3X3 matrix. I am getting error while we are providing layout_weightsum so i changed it to weightsum. still it is showing me error. I am using Andorid Studio.
Below is my 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:id="#+id/third_screen">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/scroll_screen3"
android:layout_alignParentTop="true"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/retreat_2"
android:id="#+id/screen3_view">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="CHOOSE YOUR RETREAT"
android:id="#+id/txt_welcome"
android:focusableInTouchMode="false"
android:layout_gravity="center_horizontal"
android:textSize="20sp"
android:textColor="#ffffffff"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="10dp"
android:gravity="center_horizontal" />
<ImageView
android:layout_width="match_parent"
android:layout_height="40dp"
android:id="#+id/hover"
android:src="#drawable/hover"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp" />
<LinearLayout
android:background="#drawable/outline1"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="418dp"
android:layout_margin="20dp"
android:weightsum="3"
android:id="#+id/outline_pockets" >
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="#+id/first_line_pockets"
android:layout_weightsum="3"
android:layout_weight="1"
android:layout_marginTop="10dp">
<ImageView
android:layout_width="60dp"
android:layout_height="80dp"
android:id="#+id/pocket11"
android:src="#drawable/img1"
android:layout_weight="1" />
<ImageView
android:layout_width="60dp"
android:layout_height="80dp"
android:id="#+id/pocket12"
android:src="#drawable/img2"
android:layout_weight="1" />
<ImageView
android:layout_width="60dp"
android:layout_height="80dp"
android:id="#+id/pocket13"
android:src="#drawable/img3"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/first_line_txt"
android:layout_gravity="center_vertical"
android:weightsum="3" >
<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="UNREASONABLE JOY"
android:layout_gravity="center_horizontal"
android:lines="2"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:gravity="center_vertical|center_horizontal"
android:textSize="13sp"
android:layout_weight="1"
android:id="#+id/txt_pocket11" />
<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="LIGHTEN UP"
android:layout_gravity="center_horizontal"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:gravity="center_vertical|center_horizontal"
android:textSize="13sp"
android:layout_weight="1"
android:id="#+id/txt_pocket12" />
<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="RELEASING DISEASE"
android:id="#+id/txt_pocket13"
android:lines="2"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:layout_gravity="center_horizontal"
android:gravity="center_vertical|center_horizontal"
android:textSize="13sp"
android:textIsSelectable="false"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/second_line_pockets"
android:weightsum="3"
android:layout_weight="1">
<ImageView
android:layout_width="60dp"
android:layout_height="80dp"
android:id="#+id/pocket21"
android:src="#drawable/img4"
android:layout_weight="1" />
<ImageView
android:layout_width="60dp"
android:layout_height="80dp"
android:id="#+id/pocket22"
android:src="#drawable/img5"
android:layout_weight="1" />
<ImageView
android:layout_width="60dp"
android:layout_height="80dp"
android:id="#+id/pocket23"
android:src="#drawable/img6"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:id="#+id/second_line_txt"
android:weightsum="3" >
<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="BEYOND FEVER"
android:autoText="false"
android:lines="2"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="13sp"
android:gravity="center_vertical|center_horizontal"
android:layout_weight="1"
android:id="#+id/txt_pocket21" />
<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="UNSHAKEABLE LOVE"
android:layout_gravity="center_horizontal"
android:lines="2"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="13sp"
android:gravity="center_vertical|center_horizontal"
android:layout_weight="1"
android:id="#+id/txt_pocket22" />
<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="PEACEFUL PARENTING"
android:textSize="13sp"
android:lines="2"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:layout_gravity="center_horizontal"
android:gravity="center_vertical|center_horizontal"
android:layout_weight="1"
android:id="#+id/txt_pocket23" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/third_line_pockets"
android:weightsum="3"
android:layout_weight="1">
<ImageView
android:layout_width="60dp"
android:layout_height="80dp"
android:id="#+id/pocket31"
android:src="#drawable/img7"
android:layout_weight="1" />
<ImageView
android:layout_width="60dp"
android:layout_height="80dp"
android:id="#+id/pocket32"
android:src="#drawable/img8"
android:layout_weight="1" />
<ImageView
android:layout_width="60dp"
android:layout_height="80dp"
android:id="#+id/pocket33"
android:src="#drawable/img9"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/third_line_txt"
android:weightsum="3"
android:layout_marginBottom="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="GETTING UNSTUCK"
android:autoText="false"
android:layout_gravity="center_vertical"
android:lines="2"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:gravity="center_vertical|center_horizontal"
android:textIsSelectable="false"
android:textSize="13sp"
android:layout_weight="1"
android:id="#+id/txt_pocket31" />
<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="WARRIOR MONK"
android:lines="2"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:layout_gravity="center_vertical"
android:gravity="center_vertical|center_horizontal"
android:textSize="13sp"
android:layout_weight="1"
android:id="#+id/txt_pocket32" />
<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="FILLING YOUR CUP"
android:lines="2"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:layout_gravity="center_vertical"
android:gravity="center_vertical|center_horizontal"
android:textSize="13sp"
android:singleLine="false"
android:layout_weight="1"
android:id="#+id/txt_pocket33" />
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="80dp"
android:id="#+id/no_more"
android:src="#drawable/no_more"
android:layout_marginTop="10dp" />
<ImageView
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/retreat_quiz"
android:src="#drawable/retreat_quiz"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
The correct spelling for the attribute is weightSum, not weightsum or layout_weightsum.
However, the system can calculate the sum for you. You can just omit the attribute altogether.

Categories

Resources