I'm using Android Studio to try and design a view with a GridLayout at the, a GridView in the middle and a Button at the bottom.
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="#dimen/margin"
android:layout_weight=".1"
android:orientation="vertical">
<RadioGroup
android:id="#+id/deliveryType"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin"
android:orientation="horizontal"
app:layout_constraintTop_toTopOf="parent">
<RadioButton
android:id="#+id/radWaitingOption"
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/waiting" />
<RadioButton
android:id="#+id/radCollectionOption"
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/collection" />
<RadioButton
android:id="#+id/radDeliveryOption"
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/delivery" />
</RadioGroup>
<GridLayout
android:id="#+id/customerDetails"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin">
<TextView
style="#style/caption"
android:layout_column="0"
android:layout_columnWeight=".1"
android:text="#string/name" />
<TextView
android:id="#+id/customerName"
style="#style/text"
android:layout_column="1"
android:layout_columnWeight=".5"
android:text="#string/name" />
<TextView
style="#style/caption"
android:layout_row="1"
android:layout_column="0"
android:layout_columnWeight=".1"
android:text="#string/address" />
<TextView
android:id="#+id/customerAddress"
style="#style/text"
android:layout_row="1"
android:layout_column="1"
android:layout_columnWeight=".5"
android:lines="4"
android:maxLines="4"
android:text="#string/address" />
<TextView
style="#style/caption"
android:layout_row="2"
android:layout_column="0"
android:layout_columnWeight=".1"
android:text="#string/phone" />
<TextView
android:id="#+id/customerPhone"
style="#style/text"
android:layout_row="2"
android:layout_column="1"
android:layout_columnWeight=".5"
android:text="#string/phone" />
</GridLayout>
<RadioGroup
android:id="#+id/deliveryCost"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin"
android:orientation="horizontal"
app:layout_constraintTop_toBottomOf="#id/customerDetails">
<RadioButton
android:id="#+id/radLocalOption"
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/_2_00" />
<RadioButton
android:id="#+id/radNearOption"
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/_2_50" />
<RadioButton
android:id="#+id/radFarOption"
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/_3_00" />
</RadioGroup>
</LinearLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="#dimen/margin"
android:layout_weight=".1"
android:orientation="vertical">
<GridLayout
android:id="#+id/filter"
android:layout_width="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_height="wrap_content">
<TextView
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_margin="#dimen/margin"
android:text="#string/filter" />
<EditText
android:id="#+id/txtFilter"
style="#style/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_margin="#dimen/margin"
android:hint="#string/filter_customers" />
</GridLayout>
<GridView
style="#style/margin"
android:id="#+id/customers"
app:layout_constraintTop_toBottomOf="#id/filter"
app:layout_constraintBottom_toTopOf="#+id/addButton"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_width="wrap_content"
android:layout_height="0dp">
</GridView>
<Button
style="#style/margin"
android:id="#+id/addButton"
android:layout_width="wrap_content"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_height="wrap_content"
android:text="Add"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
In the Android Studio designer it appears as I would expect:
but when it shows in the Android emulator, the Gridview appears to be expanded over the bottom of the screen and the button is not showing.
Can any give me pointers to what I have done wrong. Bare in mind this is my first attempt and a Kotlin program, coming from a dotnet background. Layout is so much easier in XAML :)
If you want the LinearLayout, ConstraintLayout and the button to stack up on top of each other, this should do it. It may need a bit of change on your end.
Replace your XML code with this and check:
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:baselineAligned="false">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="#dimen/margin"
android:layout_weight=".1"
android:orientation="vertical">
<RadioGroup
android:id="#+id/deliveryType"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin"
android:orientation="horizontal"
app:layout_constraintTop_toTopOf="parent">
<RadioButton
android:id="#+id/radWaitingOption"
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/waiting" />
<RadioButton
android:id="#+id/radCollectionOption"
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/collection" />
<RadioButton
android:id="#+id/radDeliveryOption"
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/delivery" />
</RadioGroup>
<GridLayout
android:id="#+id/customerDetails"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin">
<TextView
style="#style/caption"
android:layout_column="0"
android:layout_columnWeight=".1"
android:text="#string/name" />
<TextView
android:id="#+id/customerName"
style="#style/text"
android:layout_column="1"
android:layout_columnWeight=".5"
android:text="#string/name" />
<TextView
style="#style/caption"
android:layout_row="1"
android:layout_column="0"
android:layout_columnWeight=".1"
android:text="#string/address" />
<TextView
android:id="#+id/customerAddress"
style="#style/text"
android:layout_row="1"
android:layout_column="1"
android:layout_columnWeight=".5"
android:lines="4"
android:maxLines="4"
android:text="#string/address" />
<TextView
style="#style/caption"
android:layout_row="2"
android:layout_column="0"
android:layout_columnWeight=".1"
android:text="#string/phone" />
<TextView
android:id="#+id/customerPhone"
style="#style/text"
android:layout_row="2"
android:layout_column="1"
android:layout_columnWeight=".5"
android:text="#string/phone" />
</GridLayout>
<RadioGroup
android:id="#+id/deliveryCost"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin"
android:orientation="horizontal"
app:layout_constraintTop_toBottomOf="#id/customerDetails">
<RadioButton
android:id="#+id/radLocalOption"
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/_2_00" />
<RadioButton
android:id="#+id/radNearOption"
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/_2_50" />
<RadioButton
android:id="#+id/radFarOption"
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/_3_00" />
</RadioGroup>
</LinearLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="#dimen/margin"
android:layout_weight=".1"
android:orientation="vertical">
<GridLayout
android:id="#+id/filter"
android:layout_width="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_height="wrap_content">
<TextView
style="#style/caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_margin="#dimen/margin"
android:text="#string/filter" />
<EditText
android:id="#+id/txtFilter"
style="#style/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_margin="#dimen/margin"
android:hint="#string/filter_customers" />
</GridLayout>
<GridView
style="#style/margin"
android:id="#+id/customers"
app:layout_constraintTop_toBottomOf="#id/filter"
app:layout_constraintBottom_toTopOf="#+id/addButton"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_width="wrap_content"
android:layout_height="0dp">
</GridView>
</androidx.constraintlayout.widget.ConstraintLayout>
<Button
style="#style/margin"
android:id="#+id/addButton"
android:layout_width="wrap_content"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_height="wrap_content"
android:text="Add"/>
</LinearLayout>
Related
My app's button positions changes on different devices. Sometimes buttons are getting bigger, sometimes getting smaller,sometimes a part of buttons arent visible. I use vertical linear layout. Buttons are in drawable folder and button sizes are 227x231 px.
There are some sample screenshots. Pixel 2 - Pixel 3a - Mi 9T Pro
How can i fix ?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/back4">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="95dp"
android:background="#drawable/a"
android:orientation="horizontal">
<TextView
android:id="#+id/teamName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="15dp"
android:layout_weight="1"
android:fontFamily="#font/andika"
android:paddingTop="20dp"
android:text="Team 1"
android:textAlignment="center"
android:textColor="#000000"
android:textSize="20sp" />
<TextView
android:id="#+id/score"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="15dp"
android:layout_weight="1"
android:paddingLeft="50dp"
android:text="5"
android:textColor="#303f9f"
android:textSize="36sp"
android:textStyle="bold" />
<TextView
android:id="#+id/roundText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="15dp"
android:layout_weight="1"
android:fontFamily="#font/andika"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:text="Round 1/5"
android:textAlignment="viewStart"
android:textColor="#000000"
android:textSize="20sp" />
</LinearLayout>
<TextView
android:id="#+id/timeText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:layout_marginTop="20dp"
android:layout_marginRight="100dp"
android:fontFamily="#font/arsenal_bold"
android:text="60"
android:textAlignment="center"
android:textColor="#E2DADA"
android:textSize="40sp"
android:textStyle="bold" />
<ProgressBar
android:id="#+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:progress="0"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="419dp"
android:background="#drawable/game4"
android:orientation="vertical">
<TextView
android:id="#+id/guessWord"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="80dp"
android:layout_marginTop="50dp"
android:layout_marginEnd="80dp"
android:text="Guess "
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="38sp"
android:textStyle="bold" />
<TextView
android:id="#+id/translateWord"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="80dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="80dp"
android:text="(Translate)"
android:textAlignment="center"
android:textColor="#D0FFFFFF"
android:textSize="26sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tabuWord1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="80dp"
android:layout_marginTop="35dp"
android:layout_marginEnd="80dp"
android:text="TextView"
android:textAlignment="center"
android:textSize="30sp" />
<TextView
android:id="#+id/tabuWord2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="80dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="80dp"
android:text="TextView"
android:textAlignment="center"
android:textSize="30sp" />
<TextView
android:id="#+id/tabuWord3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="80dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="80dp"
android:text="TextView"
android:textAlignment="center"
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="123dp"
android:orientation="horizontal">
<Button
android:id="#+id/tabuButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginTop="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="30dp"
android:layout_weight="1"
android:background="#drawable/tabubutton2" />
<Button
android:id="#+id/passButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="30dp"
android:layout_weight="1"
android:background="#drawable/pasbutton2" />
<Button
android:id="#+id/trueButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="30dp"
android:layout_marginBottom="30dp"
android:layout_weight="1"
android:background="#drawable/truebutton2" />
</LinearLayout>
</LinearLayout>
You should use ScrollView but if you don't want the screen scrolling you should rebuild it using ConstraintLayout
You can do it with something like this:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
style="#style/parent"
tools:ignore="MissingConstraints">
.......
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
style.xml
<style name="parent">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
</style>
I think this should work on all screens
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/back4">
<ScrollView
style="#style/parent"
tools:ignore="MissingConstraints,ScrollViewCount">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="95dp"
android:background="#drawable/a"
android:orientation="horizontal">
<TextView
android:id="#+id/teamName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="15dp"
android:layout_weight="1"
android:fontFamily="#font/andika"
android:paddingTop="20dp"
android:text="Team 1"
android:textAlignment="center"
android:textColor="#000000"
android:textSize="20sp" />
<TextView
android:id="#+id/score"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="15dp"
android:layout_weight="1"
android:paddingLeft="50dp"
android:text="5"
android:textColor="#303f9f"
android:textSize="36sp"
android:textStyle="bold" />
<TextView
android:id="#+id/roundText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="15dp"
android:layout_weight="1"
android:fontFamily="#font/andika"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:text="Round 1/5"
android:textAlignment="viewStart"
android:textColor="#000000"
android:textSize="20sp" />
</LinearLayout>
<TextView
android:gravity="center"
android:layout_gravity="center"
android:id="#+id/timeText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="#font/arsenal_bold"
android:text="60"
android:textAlignment="center"
android:textColor="#E2DADA"
android:textSize="40sp"
android:textStyle="bold" />
<ProgressBar
android:id="#+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:progress="0"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/game4"
android:orientation="vertical">
<TextView
android:layout_margin="25dp"
android:id="#+id/guessWord"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Guess "
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="38sp"
android:textStyle="bold" />
<TextView
android:layout_margin="15dp"
android:id="#+id/translateWord"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="(Translate)"
android:textAlignment="center"
android:textColor="#D0FFFFFF"
android:textSize="26sp"
android:textStyle="bold" />
<TextView
android:layout_margin="15dp"
android:id="#+id/tabuWord1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView"
android:textAlignment="center"
android:textSize="30sp" />
<TextView
android:layout_margin="15dp"
android:id="#+id/tabuWord2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView"
android:textAlignment="center"
android:textSize="30sp" />
<TextView
android:layout_margin="15dp"
android:id="#+id/tabuWord3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView"
android:textAlignment="center"
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:layout_marginTop="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_margin="25dp"
android:id="#+id/tabuButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/tabubutton2" />
<Button
android:layout_margin="25dp"
android:id="#+id/passButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/pasbutton2" />
<Button
android:layout_margin="25dp"
android:id="#+id/trueButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/truebutton2" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
I want to create some 4 grid layout which is have Constraint Layout as a root layout. The file is created to be as a fragment, but I think that won't be a problem, mentioned in title to describe it as detail as possible.
The xml file is looked like this:
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorPrimaryLight"
tools:context=".view.LoanDetail">
<View
android:id="#+id/divider_loan"
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_marginTop="8dp"
android:background="#drawable/line_white"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:baselineAligned="false"
android:orientation="horizontal"
android:weightSum="2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/divider_loan">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center">
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:drawableEnd="#drawable/ic_money_outl"
android:drawablePadding="#dimen/margin16"
android:gravity="center"
android:text="Total Pinjaman"
android:textColor="#color/white" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="start|center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/tv_currency_dep"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginEnd="#dimen/margin8"
android:gravity="center|clip_vertical"
android:text="IDR"
android:textColor="#color/white"
android:textSize="12sp" />
<TextView
android:id="#+id/TEXTVIEW"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginEnd="#dimen/margin8"
android:gravity="center_vertical"
android:text="100,000,000"
android:textColor="#color/white"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
<GridLayout
android:id="#+id/gridLayout"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="#dimen/margin16"
android:alignmentMode="alignMargins"
android:columnCount="2"
android:columnOrderPreserved="false"
android:padding="#dimen/margin8"
android:rowCount="2"
app:layout_constraintBottom_toTopOf="#+id/linearLayout4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linearLayout3">
<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_marginStart="#dimen/margin8"
android:layout_marginEnd="#dimen/margin8"
android:layout_marginBottom="#dimen/margin8"
app:cardCornerRadius="#dimen/margin8"
app:cardElevation="#dimen/margin8">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingStart="#dimen/margin8"
android:paddingTop="#dimen/margin16"
android:paddingEnd="#dimen/margin8"
android:paddingBottom="#dimen/margin8">
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pokok"
android:textColor="#color/black" />
<TextView
android:id="#+id/textView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/margin24"
android:text="IDR"
android:textColor="#color/colorPrimaryLight"
android:textSize="12sp" />
<TextView
android:id="#+id/tv_loan_det_prim"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/margin8"
android:layout_marginTop="#dimen/margin8"
android:text="100,000,000"
android:textColor="#color/colorPrimaryLight"
android:textSize="18sp" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_marginStart="#dimen/margin8"
android:layout_marginEnd="#dimen/margin8"
android:layout_marginBottom="#dimen/margin8"
app:cardCornerRadius="#dimen/margin8"
app:cardElevation="#dimen/margin8">
<LinearLayout
android:id="#+id/rel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingStart="#dimen/margin8"
android:paddingTop="#dimen/margin16"
android:paddingEnd="#dimen/margin8"
android:paddingBottom="#dimen/margin8">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/textView14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Angsuran"
android:textColor="#color/black" />
<TextView
android:id="#+id/textView15"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/margin8"
android:layout_marginEnd="#dimen/margin8"
android:text="TERTUNGGAK"
android:textColor="#color/colorAccent"
android:textSize="10sp" />
</LinearLayout>
<TextView
android:id="#+id/textView16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/margin24"
android:text="IDR"
android:textColor="#color/colorPrimaryLight"
android:textSize="12sp" />
<TextView
android:id="#+id/textView17"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/margin8"
android:layout_marginTop="#dimen/margin8"
android:text="500,000"
android:textColor="#color/colorAccent"
android:textSize="18sp" />
<Button
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="36dp"
android:layout_marginStart="#dimen/margin8"
android:layout_marginTop="#dimen/margin8"
android:layout_marginEnd="#dimen/margin8"
android:background="#drawable/bg_green_primary"
android:text="BAYARAN"
android:textColor="#color/white" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_marginStart="#dimen/margin8"
android:layout_marginEnd="#dimen/margin8"
android:layout_marginBottom="#dimen/margin8"
app:cardCornerRadius="#dimen/margin8"
app:cardElevation="#dimen/margin8">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingStart="#dimen/margin8"
android:paddingTop="#dimen/margin16"
android:paddingEnd="#dimen/margin8"
android:paddingBottom="#dimen/margin8">
<TextView
android:id="#+id/textView18"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sisa Plafon"
android:textColor="#color/black" />
<TextView
android:id="#+id/textView19"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/margin24"
android:text="IDR"
android:textColor="#color/colorPrimaryLight"
android:textSize="12sp" />
<TextView
android:id="#+id/textView20"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/margin8"
android:layout_marginTop="#dimen/margin8"
android:text="9,500,000"
android:textColor="#color/colorPrimaryLight"
android:textSize="18sp" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_marginStart="#dimen/margin8"
android:layout_marginEnd="#dimen/margin8"
android:layout_marginBottom="#dimen/margin8"
app:cardCornerRadius="#dimen/margin8"
app:cardElevation="#dimen/margin8">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_rowWeight="1"
android:orientation="vertical"
android:paddingStart="#dimen/margin8"
android:paddingTop="#dimen/margin16"
android:paddingEnd="#dimen/margin8"
android:paddingBottom="#dimen/margin8">
<TextView
android:id="#+id/textView21"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Tenor/Bunga Bulanan"
android:textColor="#color/black" />
<TextView
android:id="#+id/textView22"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/margin8"
android:layout_marginTop="#dimen/margin24"
android:text="12 / 0.50%"
android:textColor="#color/colorPrimaryLight"
android:textSize="18sp" />
</LinearLayout>
</android.support.v7.widget.CardView>
</GridLayout>
<LinearLayout
android:id="#+id/linearLayout4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="16dp"
android:background="#drawable/bg_green_dark"
android:orientation="horizontal"
android:padding="#dimen/margin16"
android:weightSum="4"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent">
<TextView
android:id="#+id/textView9"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableTop="#drawable/ic_list_inactive"
android:gravity="center"
android:text="Senarai Simpanan"
android:textColor="#color/grey_inactive" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:clickable="true"
android:drawableTop="#drawable/ic_apps"
android:focusable="true"
android:gravity="center"
android:text="Detil"
android:textColor="#color/white" />
<TextView
android:id="#+id/textView11"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:drawableTop="#drawable/ic_history_inactive"
android:gravity="center"
android:text="Transaksi"
android:textColor="#color/grey_inactive" />
<TextView
android:id="#+id/textView13"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:drawableTop="#drawable/ic_pen_inactive"
android:gravity="center"
android:text="Aplikasi Baru"
android:textColor="#color/grey_inactive" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
And it should be looked like this (screenshot taken from Android Studio preview)
But the output in the real device the Grid layout is not showing.
Is there a thing I miss?
#Note: The rest layout is showed just fine no problem, only the GridLayout.
Please set the height and width of the GridLayout, where you didn't define, please copy and paste the code as it is which is given below it will definitely work.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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"
xmlns:app="http://schemas.android.com/apk/res-auto">
<GridLayout
android:id="#+id/gridLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:alignmentMode="alignMargins"
android:columnCount="2"
android:columnOrderPreserved="false"
android:rowCount="2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:ignore="MissingConstraints">
<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pokok"
android:textColor="#color/black" />
<TextView
android:id="#+id/textView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="IDR"
android:textSize="12sp" />
<TextView
android:id="#+id/tv_loan_det_prim"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="100,000,000"
android:textSize="18sp" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
>
<LinearLayout
android:id="#+id/rel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/textView14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Angsuran"
android:textColor="#color/black" />
<TextView
android:id="#+id/textView15"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TERTUNGGAK"
android:textColor="#color/colorAccent"
android:textSize="10sp" />
</LinearLayout>
<TextView
android:id="#+id/textView16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="IDR"
android:textSize="12sp" />
<TextView
android:id="#+id/textView17"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="500,000"
android:textColor="#color/colorAccent"
android:textSize="18sp" />
<Button
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="36dp"
android:text="BAYARAN"
android:textColor="#color/white" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:id="#+id/textView18"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sisa Plafon"
android:textColor="#color/black" />
<TextView
android:id="#+id/textView19"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="IDR"
android:textSize="12sp" />
<TextView
android:id="#+id/textView20"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="9,500,000"
android:textSize="18sp" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_rowWeight="1"
android:orientation="horizontal">
<TextView
android:id="#+id/textView21"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Tenor/Bunga Bulanan"
android:textColor="#color/black" />
<TextView
android:id="#+id/textView22"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="12 / 0.50%"
android:textSize="18sp" />
</LinearLayout>
</android.support.v7.widget.CardView>
</GridLayout>
</android.support.constraint.ConstraintLayout>
implementation 'com.android.support:support-v4:28.0.0'
implementation'com.android.support:design:28.0.0'
I am developing a feedback application which should has similar layout to this screen. [1]: https://i.stack.imgur.com/xn3kh.jpg
I have designed the xml for 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:background="#000"
android:orientation="vertical"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.zankrutparmar.feedback.Frag_one">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/frag_one_title"
android:textColor="#fff"
android:textStyle="bold|italic"
android:textSize="35dp"
android:textAlignment="center"/>
<LinearLayout
android:layout_width="819dp"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:layout_marginBottom="#dimen/activity_vertical_margin"
android:layout_marginEnd="#dimen/activity_vertical_margin"
android:text="Poor"
android:textAlignment="center"
android:textColor="#fff"
android:textSize="35dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/activity_vertical_margin"
android:text="Average"
android:textAlignment="center"
android:textColor="#fff"
android:textSize="35dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/activity_vertical_margin"
android:text="Good"
android:textAlignment="center"
android:textColor="#fff"
android:textSize="35dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/activity_vertical_margin"
android:text="Very Good"
android:textAlignment="center"
android:textColor="#fff"
android:textSize="35dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/activity_vertical_margin"
android:text="Excellent"
android:textAlignment="center"
android:textColor="#fff"
android:textSize="35dp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="6">
<TextView
android:layout_width="58dp"
android:layout_height="wrap_content"
android:layout_margin="#dimen/activity_vertical_margin"
android:layout_weight="1"
android:text="Theme & Decor"
android:textAlignment="center"
android:textColor="#fff"
android:textSize="25dp"
android:textStyle="bold|italic" />
<RadioGroup
android:id="#+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/activity_vertical_margin"
android:layout_weight="5"
android:orientation="horizontal">
<RadioButton
android:id="#+id/poor1"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#drawable/custom_btn_radio_poor"
android:button="#null" />
<RadioButton
android:id="#+id/average1"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#drawable/custom_btn_radio_average"
android:button="#null" />
<RadioButton
android:id="#+id/good1"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#drawable/custom_btn_radio_good"
android:button="#null" />
<RadioButton
android:id="#+id/very1"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#drawable/custom_btn_radio_very_good"
android:button="#null" />
<RadioButton
android:id="#+id/excellent1"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#drawable/custom_btn_radio_excellent"
android:button="#null" />
</RadioGroup>
</LinearLayout>
Now whenever I want to apply margin to these radio buttons the center one remains in center and pushes all other buttons far.
I also tried the answers on this question [1]: TableLayout of radiogroup(s) with respective label(s) aligned in android
But in that layout the problem is all buttons in single row are getting selected. It means Radiogroup can't be placed in that layout.
And I have to fetch questions from a database and place them in my application.
So in Future I will have to add rows dynamically.
Any help will be very appreciated. Thank you in advance.
Okay I designed a new layout and fixed those previous issues. I am uploading that 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:background="#8bae3a"
tools:context="com.zankrutparmar.feedback.Frag_two">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:layout_width="match_parent"
android:layout_marginLeft="20dp"
android:layout_height="match_parent" >
<TextView
android:id="#+id/textView5"
android:layout_column="1"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/textView10"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/textView9"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/textView6"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="TextView" />
</TableRow>
<TableRow
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<RadioGroup
android:layout_marginLeft="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:orientation="horizontal">
<RadioButton
style="#style/MyRadioButtonStyle"
android:gravity="center"
android:padding="8dp"
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<RadioButton
style="#style/MyRadioButtonStyle"
android:gravity="center"
android:paddingLeft="8dp"
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
style="#style/MyRadioButtonStyle"
android:gravity="center"
android:paddingLeft="8dp"
android:layout_marginLeft="5dp"
/>
<RadioButton
style="#style/MyRadioButtonStyle"
android:gravity="center"
android:paddingLeft="8dp"
android:layout_marginLeft="7dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
</RadioGroup>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<RadioGroup
android:layout_marginLeft="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:orientation="horizontal">
<RadioButton
style="#style/MyRadioButtonStyle"
android:gravity="center"
android:padding="8dp"
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<RadioButton
style="#style/MyRadioButtonStyle"
android:gravity="center"
android:paddingLeft="8dp"
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
style="#style/MyRadioButtonStyle"
android:gravity="center"
android:paddingLeft="8dp"
android:layout_marginLeft="5dp"
/>
<RadioButton
style="#style/MyRadioButtonStyle"
android:gravity="center"
android:paddingLeft="8dp"
android:layout_marginLeft="7dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
</RadioGroup>
</TableRow>
</TableLayout>
This is the my current listivew:
My problem is i can't display my last item in the list. It's like getting cut by my phone.
Here is the xml code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<RelativeLayout
android:orientation="vertical"
android:id="#+id/border"
android:layout_width="match_parent"
android:layout_height="280dp"
android:background="#drawable/dfcomment3"
android:layout_weight="0.07">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="Add comment"
android:id="#+id/button12"
android:layout_marginTop="215dp"
android:layout_marginLeft="5dp" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="Update Post"
android:id="#+id/button13"
android:layout_marginTop="215dp" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="Close This"
android:id="#+id/button14"
android:layout_marginTop="215dp" />
</LinearLayout>
<TextView
android:layout_marginLeft="10dp"
android:textSize="35dp"
android:id="#+id/textView11"
android:gravity="center"
android:text="ID"
android:textStyle="bold"
android:textColor="#994495"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView12"
android:text="Name"
android:textSize="16dp"
android:textColor="#994495"
android:layout_marginTop="190dp"
android:layout_marginLeft="210dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView13"
android:text="Lastname"
android:textStyle="bold"
android:textSize="16dp"
android:layout_marginLeft="90dp"
android:textColor="#994495"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/id"
android:layout_toEndOf="#+id/id"
android:layout_marginTop="5dp" />
<TextView
android:id="#+id/textView14"
android:text="title"
android:textSize="15dp"
android:textColor="#994495"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="260dp"
android:layout_below="#+id/name"
android:layout_alignStart="#+id/name"
android:layout_marginTop="190dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="descr"
android:textSize="21dp"
android:textColor="#994495"
android:id="#+id/textView15"
android:layout_marginLeft="110dp"
android:layout_marginTop="60dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="dept"
android:textStyle="italic"
android:textColor="#994495"
android:id="#+id/textView16"
android:layout_marginLeft="180dp"
android:layout_marginTop="30dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="tags"
android:textStyle="italic"
android:textSize="14dp"
android:textColor="#994495"
android:id="#+id/textView17"
android:layout_marginLeft="120dp"
android:layout_marginTop="30dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="status"
android:textSize="25dp"
android:textStyle="bold"
android:textColor="#70CC86"
android:id="#+id/textView18"
android:layout_marginLeft="290dp"
android:layout_marginTop="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="date"
android:textColor="#994495"
android:id="#+id/textView19"
android:layout_marginLeft="10dp"
android:layout_marginTop="190dp" />
</RelativeLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="match_parent" >
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>
As much as possible i want to stick with the listview because i'm not familiar with the recyclerview. if theres any way to fix this, i would be glad.
Check the image for the reference of my problem.
There's actually 4 items in the list and i can only view 2 items.
Firstly there is problem with your XML as when you use weightsum and layout_weight then you need not give dimensions in height or width.
This must be your XML.
Also I checked your XML there is some problem in you XML attributes too. Like you used "android:layout_below="#+id/id"" but in your xml there is no "id"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="100">
<RelativeLayout
android:orientation="vertical"
android:id="#+id/border"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#drawable/dfcomment3"
android:layout_weight="70">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="Add comment"
android:id="#+id/button12"
android:layout_marginTop="215dp"
android:layout_marginLeft="5dp" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="Update Post"
android:id="#+id/button13"
android:layout_marginTop="215dp" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="Close This"
android:id="#+id/button14"
android:layout_marginTop="215dp" />
</LinearLayout>
<TextView
android:layout_marginLeft="10dp"
android:textSize="35dp"
android:id="#+id/textView11"
android:gravity="center"
android:text="ID"
android:textStyle="bold"
android:textColor="#994495"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView12"
android:text="Name"
android:textSize="16dp"
android:textColor="#994495"
android:layout_marginTop="190dp"
android:layout_marginLeft="210dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView13"
android:text="Lastname"
android:textStyle="bold"
android:textSize="16dp"
android:layout_marginLeft="90dp"
android:textColor="#994495"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/id"
android:layout_toEndOf="#+id/id"
android:layout_marginTop="5dp" />
<TextView
android:id="#+id/textView14"
android:text="title"
android:textSize="15dp"
android:textColor="#994495"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="260dp"
android:layout_below="#+id/name"
android:layout_alignStart="#+id/name"
android:layout_marginTop="190dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="descr"
android:textSize="21dp"
android:textColor="#994495"
android:id="#+id/textView15"
android:layout_marginLeft="110dp"
android:layout_marginTop="60dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="dept"
android:textStyle="italic"
android:textColor="#994495"
android:id="#+id/textView16"
android:layout_marginLeft="180dp"
android:layout_marginTop="30dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="tags"
android:textStyle="italic"
android:textSize="14dp"
android:textColor="#994495"
android:id="#+id/textView17"
android:layout_marginLeft="120dp"
android:layout_marginTop="30dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="status"
android:textSize="25dp"
android:textStyle="bold"
android:textColor="#70CC86"
android:id="#+id/textView18"
android:layout_marginLeft="290dp"
android:layout_marginTop="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="date"
android:textColor="#994495"
android:id="#+id/textView19"
android:layout_marginLeft="10dp"
android:layout_marginTop="190dp" />
</RelativeLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_weight="30"
android:layout_height="0dp" >
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
</LinearLayout>
Add your java code if you are not getting 4 values into your ListView
Change you xml to :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<RelativeLayout
android:orientation="vertical"
android:id="#+id/border"
android:layout_width="match_parent"
android:layout_height="280dp"
android:layout_weight="0.07"--> Delete this
>
....
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_weight="1" -> Add this
android:layout_height="0dp" >
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>
Ok, after trying any solution I found I decided to put my code in here for help.
I get HTML from JSON and I place it in a TextView to show it.
This is it:
hoursTextView.setText(Html.fromHtml(hours));
hoursTextView.setVisibility(View.VISIBLE);
My problem is, that whenever the content above this TextView takes alot of height, I see only cutted top letters of this TextView and I can't scroll down!
This is my Layout XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
>
<ProgressBar
android:id="#+id/loadData"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="50dp"
android:layout_centerInParent="true"
/>
<ImageView
android:id="#+id/coverImg"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#000000"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:layout_marginBottom="5dp"
/>
<TextView
android:id="#+id/fbAbout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/coverImg"
android:gravity="center"
/>
<View
android:id="#+id/seperator"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#eeeeee"
android:layout_below="#+id/fbAbout"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
/>
<LinearLayout
android:id="#+id/buttons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/seperator"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
>
<TextView
android:id="#+id/type"
android:layout_width="0dp"
android:layout_height="70dp"
android:background="#drawable/circle_text"
android:textAlignment="center"
android:gravity="center"
android:padding="10dp"
android:drawableTop="#drawable/beer"
android:drawablePadding="5dp"
android:text="TYPE"
android:layout_weight="1"
/>
<TextView
android:id="#+id/age"
android:layout_width="0dp"
android:layout_height="70dp"
android:background="#drawable/circle_text"
android:textAlignment="center"
android:gravity="center"
android:padding="10dp"
android:drawableTop="#drawable/age_big"
android:drawablePadding="5dp"
android:layout_marginStart="10dp"
android:text="AGE"
android:layout_weight="1"
/>
<Button
android:id="#+id/callToPlace"
android:layout_width="0dp"
android:layout_height="70dp"
android:background="#drawable/circle_text"
android:textAlignment="center"
android:gravity="center"
android:padding="10dp"
android:drawableTop="#drawable/ic_call_black_24dp"
android:drawablePadding="5dp"
android:layout_marginStart="10dp"
android:text="CALL"
android:layout_weight="1"
/>
<Button
android:id="#+id/nav"
android:layout_width="0dp"
android:layout_height="70dp"
android:background="#drawable/circle_text"
android:textAlignment="center"
android:gravity="center"
android:padding="10dp"
android:drawableTop="#drawable/navigate"
android:drawablePadding="5dp"
android:layout_marginStart="10dp"
android:text="navigate"
android:layout_weight="1"
/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="HOURS"
android:id="#+id/hoursTitle"
android:layout_below="#+id/buttons"
android:layout_centerHorizontal="true"
android:visibility="gone"
android:layout_marginTop="10dp"
/>
<!--This is the TextView which is cut -->
<TextView
android:id="#+id/hours"
android:layout_marginTop="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/hoursTitle"
android:visibility="gone"
android:layout_centerHorizontal="true"
android:gravity="center"
/>
</RelativeLayout>
The last TextView, with the ID of hours, is being cut on the bottom of the screen.
Hope someone can help me with this,
thanks!
You can use ScrollView for full screen.
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/output">
<ProgressBar
android:id="#+id/loadData"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="50dp"
android:layout_centerInParent="true"
/>
<ImageView
android:id="#+id/coverImg"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#000000"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:layout_marginBottom="5dp"
/>
<TextView
android:id="#+id/fbAbout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/coverImg"
android:gravity="center"
/>
<View
android:id="#+id/seperator"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#eeeeee"
android:layout_below="#+id/fbAbout"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
/>
<LinearLayout
android:id="#+id/buttons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/seperator"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
>
<TextView
android:id="#+id/type"
android:layout_width="0dp"
android:layout_height="70dp"
android:background="#drawable/circle_text"
android:textAlignment="center"
android:gravity="center"
android:padding="10dp"
android:drawableTop="#drawable/beer"
android:drawablePadding="5dp"
android:text="TYPE"
android:layout_weight="1"
/>
<TextView
android:id="#+id/age"
android:layout_width="0dp"
android:layout_height="70dp"
android:background="#drawable/circle_text"
android:textAlignment="center"
android:gravity="center"
android:padding="10dp"
android:drawableTop="#drawable/age_big"
android:drawablePadding="5dp"
android:layout_marginStart="10dp"
android:text="AGE"
android:layout_weight="1"
/>
<Button
android:id="#+id/callToPlace"
android:layout_width="0dp"
android:layout_height="70dp"
android:background="#drawable/circle_text"
android:textAlignment="center"
android:gravity="center"
android:padding="10dp"
android:drawableTop="#drawable/ic_call_black_24dp"
android:drawablePadding="5dp"
android:layout_marginStart="10dp"
android:text="CALL"
android:layout_weight="1"
/>
<Button
android:id="#+id/nav"
android:layout_width="0dp"
android:layout_height="70dp"
android:background="#drawable/circle_text"
android:textAlignment="center"
android:gravity="center"
android:padding="10dp"
android:drawableTop="#drawable/navigate"
android:drawablePadding="5dp"
android:layout_marginStart="10dp"
android:text="navigate"
android:layout_weight="1"
/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="HOURS"
android:id="#+id/hoursTitle"
android:layout_below="#+id/buttons"
android:layout_centerHorizontal="true"
android:visibility="gone"
android:layout_marginTop="10dp"
/>
<!--This is the TextView which is cut -->
<TextView
android:id="#+id/hours"
android:layout_marginTop="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/hoursTitle"
android:visibility="gone"
android:layout_centerHorizontal="true"
android:gravity="center"
/>
</ScrollView>
Another Example:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button 1" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button 2" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button 3" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button 4" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button 5" />
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<RadioButton
android:id="#+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RadioButton 1" />
<RadioButton
android:id="#+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RadioButton 2" />
<ToggleButton
android:id="#+id/toggleButton1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ToggleButton" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button 6" />
<SeekBar
android:id="#+id/seekBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="#+id/button3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button 7" />
<Button
android:id="#+id/button4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button 8" />
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CheckBox" />
<Button
android:id="#+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button 9" />
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button 10" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button 11" />
</LinearLayout>
</ScrollView>
Add the scroll view
<ScrollView
android:layout_width="match_parent"
android:layout_height="150dp" >
<!--Just assume it whatever your height is-->
<TextView
android:id="#+id/hours"
android:layout_marginTop="5dp"
android:layout_width="wrap_content"
android:layout_height="150dp"
android:layout_below="#+id/hoursTitle"
android:visibility="gone"
android:layout_centerHorizontal="true"
android:gravity="center"
/>
</ScrollView>