I've read this guide, but I can't figure out how to do this.
What I have is a regular chain with all the elements, chain mode "spread inside":
What I want is the buttons with the up and down arrows packed to the right side, and the "4" text spread evenly in the remaining space:
My xml:
<TextView
android:id="#+id/tv_sel_rep_1"
android:layout_width="11dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:minWidth="0dp"
android:minHeight="0dp"
android:text="#{String.valueOf(exercise.set1Reps)}"
android:textSize="24sp"
android:visibility="#{exercise.isActive && !exercise.isTimedExercise? View.VISIBLE : View.GONE}"
app:layout_constraintEnd_toStartOf="#+id/tv_sel_rep_2"
app:layout_constraintHorizontal_chainStyle="spread"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/sp_sel_exer"
tools:text="4" />
<TextView
android:id="#+id/tv_sel_rep_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="0dp"
android:minHeight="0dp"
android:text="#{String.valueOf(exercise.set2Reps)}"
android:textSize="24sp"
android:visibility="#{exercise.isActive && !exercise.isTimedExercise? View.VISIBLE : View.GONE}"
app:layout_constraintBottom_toBottomOf="#+id/tv_sel_rep_1"
app:layout_constraintEnd_toStartOf="#+id/tv_sel_rep_3"
app:layout_constraintStart_toEndOf="#+id/tv_sel_rep_1"
app:layout_constraintTop_toTopOf="#+id/tv_sel_rep_1"
tools:text="4" />
<TextView
android:id="#+id/tv_sel_rep_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="0dp"
android:minHeight="0dp"
android:text="#{String.valueOf(exercise.set3Reps)}"
android:textSize="24sp"
android:visibility="#{exercise.isActive && !exercise.isTimedExercise? View.VISIBLE : View.GONE}"
app:layout_constraintBottom_toBottomOf="#+id/tv_sel_rep_2"
app:layout_constraintEnd_toStartOf="#+id/b_sel_increase_reps_small"
app:layout_constraintStart_toEndOf="#+id/tv_sel_rep_2"
app:layout_constraintTop_toTopOf="#+id/tv_sel_rep_2"
tools:text="4" />
<TextView
android:id="#+id/tv_sel_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="0dp"
android:minHeight="0dp"
android:text="#{String.valueOf(exercise.setTime)}"
android:visibility="#{exercise.isActive && exercise.isTimedExercise? View.VISIBLE : View.GONE}"
app:layout_constraintBottom_toBottomOf="#+id/b_sel_increase_reps_small"
app:layout_constraintEnd_toStartOf="#+id/b_sel_increase_reps_small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/b_sel_increase_reps_small"
tools:text="30"
tools:visibility="gone" />
<Button
android:id="#+id/b_sel_increase_reps_small"
android:layout_width="44dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:minWidth="0dp"
android:minHeight="0dp"
android:onClick="#{() -> viewModel.incrementSet(exercise, true)}"
android:padding="16dp"
android:text="↑"
android:textSize="24sp"
android:visibility="#{exercise.isActive? View.VISIBLE: View.GONE}"
app:layout_constraintBottom_toBottomOf="#+id/tv_sel_rep_3"
app:layout_constraintEnd_toStartOf="#+id/b_sel_reduce_reps_small"
app:layout_constraintStart_toEndOf="#+id/tv_sel_rep_3"
app:layout_constraintTop_toTopOf="#+id/tv_sel_rep_3" />
<Button
android:id="#+id/b_sel_reduce_reps_small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:layout_marginEnd="8dp"
android:minWidth="0dp"
android:minHeight="0dp"
android:onClick="#{() -> viewModel.decrementSet(exercise, true)}"
android:padding="16dp"
android:text="↓"
android:textSize="24sp"
android:visibility="#{cbActiveExer.checked? View.VISIBLE: View.GONE}"
app:layout_constraintBottom_toBottomOf="#+id/b_sel_increase_reps_small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/b_sel_increase_reps_small"
app:layout_constraintTop_toTopOf="#+id/b_sel_increase_reps_small" />
I would remove the buttons from the chain and have them stick to the end of the parent by only specifying their end constraints. Now keep the TextViews in a chain with the default chainstyle (spread) and constrain its start to parent's start and its end to up-arrow's start.
Example 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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#id/textview2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/textview2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#id/textview3"
app:layout_constraintStart_toEndOf="#id/textview1"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/textview3"
android:text="4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#id/increase"
app:layout_constraintStart_toEndOf="#id/textview2"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="#+id/increase"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#android:drawable/arrow_up_float"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#id/decrease"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="#+id/decrease"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#android:drawable/arrow_down_float"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
Result:
Related
Right now I have 3 image buttons in constraint layout (not in tablelayout or gridlayout) and I want to have text under the image buttons that's centered with regards to the image buttons.
This is what I have right now:
I want to have my layout so that the Textview is centered rather than being right/left aligned with the image button.
Here's my code:
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#+id/bottomNavigationView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/topNavigationView"
>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/flFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#+id/bottomNavigationView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/topNavigationView"
app:layout_constraintVertical_bias="0.0">
<ImageButton
android:id="#+id/button"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginTop="16dp"
android:background="#xml/round_shape"
app:layout_constraintEnd_toStartOf="#+id/button2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_launcher_foreground" />
<ImageButton
android:id="#+id/button2"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginStart="10dp"
android:layout_marginTop="16dp"
android:background="#xml/round_shape"
app:layout_constraintEnd_toStartOf="#+id/button13"
app:layout_constraintStart_toEndOf="#+id/button"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_launcher_foreground" />
<ImageButton
android:id="#+id/button13"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginStart="10dp"
android:layout_marginTop="16dp"
android:background="#xml/round_shape"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/button2"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_launcher_foreground" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
app:layout_constraintEnd_toStartOf="#+id/textView2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/button" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
app:layout_constraintEnd_toStartOf="#+id/textView4"
app:layout_constraintStart_toEndOf="#+id/textView"
app:layout_constraintTop_toBottomOf="#+id/button2" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/textView2"
app:layout_constraintTop_toBottomOf="#+id/button13" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
Thanks so much.
What I want is to make the 'edit' ImageView between '6.4 MB' TextView and '···'TextView, and let 'edit' ImageView close to '···'TextView.
<RelativeLayout
android:layout_width="fill_parent"
android:layout_marginTop="15dp"
android:layout_height="match_parent">
<ImageView
android:src="#drawable/screenshot"
android:layout_width="80dp"
android:layout_height="80dp"
android:id="#+id/screenShot"
android:layout_alignParentLeft="true"
android:layout_marginRight="10dp"
/>
<TextView
android:text="Video Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:textSize="23dp"
android:textColor="#000000"
android:id="#+id/videoName"
android:layout_toRightOf="#id/screenShot"
android:layout_alignParentTop="true"
/>
<TextView
android:text="2021.05.19 · 5:11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:textSize="15dp"
android:textColor="#797675"
android:id="#+id/recordDate"
android:layout_toRightOf="#id/screenShot"
android:layout_below="#id/videoName"
/>
<TextView
android:text="6.4 MB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:textSize="15dp"
android:textColor="#797675"
android:id="#+id/videoSize"
android:layout_toRightOf="#id/screenShot"
android:layout_alignBottom="#id/screenShot"
/>
<ImageView
android:src="#drawable/edit"
android:layout_width="27dp"
android:layout_height="27dp"
android:id="#+id/edit"
android:layout_toRightOf="#id/videoSize"
android:layout_toLeftOf="#id/edit"
android:layout_alignBottom="#id/screenShot"
/>
<TextView
android:text="···"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:textSize="40dp"
android:textColor="#000000"
android:id="#+id/moreAction"
android:layout_alignBottom="#id/screenShot"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
If I use android:layout_marginLeft="40dp" in 'edit' ImageView, then the 'edit' ImageView will disappear.
Why android:layout_marginLeft is noting working?
anyone can help?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/screenShot"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_alignParentLeft="true"
android:layout_marginRight="10dp"
android:src="#drawable/ic_launcher_background" />
<TextView
android:id="#+id/videoName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="0dp"
android:layout_toRightOf="#id/screenShot"
android:text="Video Name"
android:textColor="#000000"
android:textSize="23dp" />
<TextView
android:id="#+id/recordDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/videoName"
android:layout_marginLeft="0dp"
android:layout_toRightOf="#id/screenShot"
android:text="2021.05.19 · 5:11"
android:textColor="#797675"
android:textSize="15dp" />
<TextView
android:id="#+id/videoSize"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#id/screenShot"
android:layout_marginLeft="0dp"
android:layout_toRightOf="#id/screenShot"
android:text="6.4 MB"
android:textColor="#797675"
android:textSize="15dp" />
**<ImageView
android:id="#+id/edit"
android:layout_width="27dp"
android:layout_height="27dp"
android:layout_alignBottom="#id/screenShot"
android:layout_marginRight="16dp"
android:layout_toLeftOf="#id/moreAction"
android:src="#drawable/ic_baseline_content_cut_24" />**
<TextView
android:id="#+id/moreAction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#id/screenShot"
android:layout_alignParentRight="true"
android:layout_marginLeft="0dp"
android:text="···"
android:textColor="#000000"
android:textSize="40dp" />
I shall remove
android:layout_toLeftOf="#id/edit"
and add
android:layout_marginLeft="170dp"
the complete 'edit' ImageView code is like below:
<ImageView
android:src="#drawable/edit"
android:layout_width="27dp"
android:layout_height="27dp"
android:id="#+id/edit"
android:layout_toRightOf="#id/videoSize"
android:layout_marginLeft="170dp"
android:layout_alignBottom="#id/screenShot"
/>
Is the below xml file right? I am trying to display information that I have fetched from sqlite in recycler view.
Is the below xml file right? I am trying to display information that I have fetched from sqlite in recycler view.
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="150dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView2"
android:layout_width="3dp"
android:layout_height="23dp"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.3" />
<TextView
android:id="#+id/semester"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.15"
app:layout_constraintStart_toEndOf="#+id/textView2"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.3" />
<TextView
android:id="#+id/textView32"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SGPA"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.7" />
<TextView
android:id="#+id/textView33"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Percentage"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.6"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.70" />
<TextView
android:id="#+id/textV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="#+id/textView32"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.08"
app:layout_constraintStart_toEndOf="#+id/textView32"
app:layout_constraintTop_toTopOf="#+id/textView32"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="#+id/textVw"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="#+id/textView33"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.08"
app:layout_constraintStart_toEndOf="#+id/textView33"
app:layout_constraintTop_toTopOf="#+id/textView33" />
<TextView
android:id="#+id/scheme1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.95"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.95" />
<ImageButton
android:id="#+id/btndelete1"
android:layout_width="30dp"
android:layout_height="40dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.96"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.05"
app:srcCompat="#android:drawable/ic_menu_delete" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
This is what I want:
And this is what I am getting:
I don't know why. Can someone help me out?
Also, if needed, this is where I am calling the recycler view:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
tools:context=".drawernav.bottom_navi.recycler_view.sgpa_frag">
<!-- TODO: Update blank fragment layout -->
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rc1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</androidx.recyclerview.widget.RecyclerView>
<TextView
android:id="#+id/else2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="It's a bit lonely here..."
android:gravity="center"
android:visibility="gone"/>
</FrameLayout>
Try to use this layout:
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="0dp">
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.2" />
<TextView
android:id="#+id/textView2"
android:layout_width="0dp"
android:layout_height="0dp"
android:text="1"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="#+id/btndelete1"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/btndelete1"
app:layout_constraintVertical_bias="0.3" />
<TextView
android:id="#+id/semester"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="2"
app:layout_constraintBottom_toBottomOf="#+id/textView2"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.15"
app:layout_constraintStart_toEndOf="#+id/textView2"
app:layout_constraintTop_toTopOf="#+id/textView2"
app:layout_constraintVertical_bias="0.3"
app:layout_constraintWidth_percent="0.1" />
<TextView
android:id="#+id/textView32"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="SGPA"
app:layout_constraintBottom_toTopOf="#+id/guideline"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="#+id/textView2"
app:layout_constraintHorizontal_bias="0.2"
app:layout_constraintStart_toStartOf="#+id/textView2"
app:layout_constraintTop_toBottomOf="#+id/textView2"
app:layout_constraintVertical_bias="0.7"
app:layout_constraintWidth_percent="0.1" />
<TextView
android:id="#+id/textView33"
android:layout_width="0dp"
android:layout_height="0dp"
android:text="Percentage"
app:layout_constraintBottom_toBottomOf="#+id/textView32"
app:layout_constraintEnd_toStartOf="#+id/btndelete1"
app:layout_constraintHorizontal_bias="0.6"
app:layout_constraintStart_toEndOf="#+id/semester"
app:layout_constraintTop_toTopOf="#+id/textView32"
app:layout_constraintVertical_bias="0.70"
app:layout_constraintWidth_percent="0.18" />
<TextView
android:id="#+id/textV"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="3"
app:layout_constraintBottom_toBottomOf="#+id/textView32"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="#+id/semester"
app:layout_constraintHorizontal_bias="0.08"
app:layout_constraintStart_toStartOf="#+id/semester"
app:layout_constraintTop_toTopOf="#+id/textView32"
app:layout_constraintVertical_bias="0.0"
app:layout_constraintWidth_percent="0.1" />
<TextView
android:id="#+id/textVw"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5"
app:layout_constraintBottom_toBottomOf="#+id/textView33"
app:layout_constraintEnd_toStartOf="#+id/btndelete1"
app:layout_constraintHorizontal_bias="0.08"
app:layout_constraintStart_toEndOf="#+id/textView33"
app:layout_constraintTop_toTopOf="#+id/textView33" />
<TextView
android:id="#+id/scheme1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4"
android:textSize="10sp"
app:layout_constraintEnd_toEndOf="#+id/btndelete1"
app:layout_constraintStart_toStartOf="#+id/btndelete1"
app:layout_constraintTop_toTopOf="#+id/guideline" />
<ImageButton
android:id="#+id/btndelete1"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.96"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.05"
app:layout_constraintWidth_percent="0.1"
app:srcCompat="#android:drawable/ic_menu_delete" />
</androidx.constraintlayout.widget.ConstraintLayout>
I have used those attributes to make your layout responsive:
app:layout_constraintGuide_percent="0.2"
app:layout_constraintDimensionRatio="1:1"
In addition, I added Guideline
And it will look like this:
The apps top component has 4 TableRows under a TableLayout and each has a nested TextView and a Switch.
Each of these is set to Visibility:visible
And they show as expected in the Design mode for all available resolutions say NexusS(4.0,480x800,hdpi)
but when started on my Marshmallow device of the same resolution and size, only the switches show up and in their correct positions, those 4 textviews dissappear..
(http://i.stack.imgur.com/xmPqk.png)
(http://i.stack.imgur.com/6UNBo.png)![on device]
Heres the relevant 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/MainPage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bb"
android:hapticFeedbackEnabled="false"
android:minHeight="320dp"
android:minWidth="240dp"
android:visibility="visible"
tools:context=".MainActivity">
<Button
android:id="#+id/play"
android:layout_width="120dp"
android:layout_height="34dp"
android:layout_marginBottom="188dp"
android:layout_marginEnd="205dp"
android:layout_marginStart="24dp"
android:background="#ad000000"
android:hapticFeedbackEnabled="false"
android:text="#string/playBtn"
android:textAllCaps="true"
android:textColor="#android:color/white"
android:textStyle="bold"
android:typeface="monospace"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.272"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="#+id/settings"
android:layout_width="120dp"
android:layout_height="38dp"
android:layout_marginTop="8dp"
android:background="#ad000000"
android:hapticFeedbackEnabled="false"
android:text="#string/setBtn"
android:textAllCaps="true"
android:textColor="#android:color/white"
android:textStyle="bold"
android:typeface="monospace"
android:visibility="visible"
app:layout_constraintStart_toStartOf="#+id/play"
app:layout_constraintTop_toBottomOf="#+id/play" />
<Button
android:id="#+id/quit"
android:layout_width="120dp"
android:layout_height="38dp"
android:layout_marginTop="8dp"
android:background="#ad000000"
android:hapticFeedbackEnabled="false"
android:text="#string/quitBtn"
android:textAllCaps="true"
android:textColor="#android:color/white"
android:textStyle="bold"
android:typeface="monospace"
android:visibility="visible"
app:layout_constraintStart_toStartOf="#+id/settings"
app:layout_constraintTop_toBottomOf="#+id/settings" />
<TextView
android:id="#+id/Title"
android:layout_width="wrap_content"
android:layout_height="178dp"
android:layout_marginBottom="20dp"
android:layout_marginTop="20dp"
android:fontFamily="#font/owaw"
android:textColor="#android:color/white"
android:textSize="120sp"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="#+id/play"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.418"
tools:text="#string/app_name" />
<TableLayout
android:id="#+id/OptionsLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/black"
android:gravity="center_vertical|start"
android:orientation="vertical"
android:paddingEnd="0dp"
android:paddingStart="100dp"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/Title"
app:layout_constraintVertical_bias="0.0">
<TableRow
android:id="#+id/Option1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="24dp"
android:orientation="horizontal"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="#+id/Option2"
app:layout_constraintEnd_toEndOf="#+id/Option2"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="#+id/Option2"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:layout_width="150dp"
android:layout_height="wrap_content"
android:paddingBottom="20dp"
android:textAppearance="#style/TextAppearance.AppCompat.Button"
android:textColor="#android:color/white"
android:textSize="20sp"
android:textStyle="bold"
android:visibility="visible"
tools:text="#string/opt1" />
<Switch
android:id="#+id/tutorialSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:allowUndo="true"
android:alpha="0.8"
android:background="#android:color/black"
android:checked="true"
android:hapticFeedbackEnabled="false"
android:padding="0dp"
android:showText="false"
android:splitTrack="false"
android:switchMinWidth="20dp" />
</TableRow>
<TableRow
android:id="#+id/Option2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="#+id/Option3"
app:layout_constraintEnd_toEndOf="#+id/Option3"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="#+id/Option3"
app:layout_constraintTop_toBottomOf="#+id/Option1">
<TextView
android:layout_width="150dp"
android:layout_height="wrap_content"
android:paddingBottom="20dp"
android:textAppearance="#style/TextAppearance.AppCompat.Button"
android:textColor="#android:color/white"
android:textSize="20sp"
android:textStyle="bold"
android:visibility="visible"
tools:text="#string/opt2" />
<Switch
android:id="#+id/musicSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:layout_marginEnd="-70dp"
android:allowUndo="true"
android:alpha="0.8"
android:background="#android:color/black"
android:checked="true"
android:hapticFeedbackEnabled="false"
android:padding="0dp"
android:showText="false"
android:splitTrack="false"
android:switchMinWidth="20dp" />
</TableRow>
<TableRow
android:id="#+id/Option3"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="#+id/Option4"
app:layout_constraintEnd_toEndOf="#+id/Option4"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="#+id/Option4"
app:layout_constraintTop_toBottomOf="#+id/Option2">
<TextView
android:layout_width="150dp"
android:layout_height="wrap_content"
android:paddingBottom="20dp"
android:textAppearance="#style/TextAppearance.AppCompat.Button"
android:textColor="#android:color/white"
android:textSize="20sp"
android:textStyle="bold"
android:visibility="visible"
tools:text="#string/opt3" />
<Switch
android:id="#+id/hapticSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:allowUndo="true"
android:alpha="0.8"
android:background="#android:color/black"
android:checked="false"
android:hapticFeedbackEnabled="false"
android:padding="0dp"
android:showText="false"
android:splitTrack="false"
android:switchMinWidth="20dp" />
</TableRow>
<TableRow
android:id="#+id/Option4"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="#+id/Option5"
app:layout_constraintEnd_toEndOf="#+id/Option5"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="#+id/Option5"
app:layout_constraintTop_toBottomOf="#+id/Option3">
<TextView
android:layout_width="150dp"
android:layout_height="wrap_content"
android:paddingBottom="20dp"
android:textAppearance="#style/TextAppearance.AppCompat.Button"
android:textColor="#android:color/white"
android:textSize="20sp"
android:textStyle="bold"
android:visibility="visible"
tools:text="#string/opt4" />
<Switch
android:id="#+id/sfxSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:allowUndo="true"
android:alpha="0.8"
android:background="#android:color/black"
android:checked="true"
android:hapticFeedbackEnabled="true"
android:padding="0dp"
android:showText="false"
android:splitTrack="false"
android:switchMinWidth="20dp" />
</TableRow>
<TableRow
android:id="#+id/Option5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/Option4">
<TextView
android:id="#+id/saveOption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="60dp"
android:layout_marginTop="20dp"
android:clickable="true"
android:focusable="true"
android:hapticFeedbackEnabled="false"
android:paddingBottom="20dp"
android:textAppearance="#style/TextAppearance.AppCompat.Button"
android:textColor="#android:color/white"
android:textSize="20sp"
android:textStyle="bold"
android:visibility="visible"
tools:text="#string/opt5" />
</TableRow>
</TableLayout>
</android.support.constraint.ConstraintLayout>
UPDATE:
I added the font family property to each of those and now the text is visible on device but I dont understand how it matters, since there is already a default option there.
I'm developing a form for an App: I've added some Textview fields having width set to "wrap to content" but anyway I try to modify the width the Textview size is always bigger than content. Even using Android Graphical Layout it prevents me from resizing TextViews and EditText.
Here is the layout xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#0099cc"
tools:context=".ModuloAlfa" >
<!--
The primary full-screen view. This can be replaced with whatever view
is needed to present your content, e.g. VideoView, SurfaceView,
TextureView, etc.
-->
<TextView
android:id="#+id/fullscreen_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:keepScreenOn="true"
android:text="#string/dummy_content"
android:textColor="#33b5e5"
android:textSize="50sp"
android:textStyle="bold" />
<!--
This FrameLayout insets its children based on system windows using
android:fitsSystemWindows.
-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:text="#string/NModulo" />
<EditText
android:id="#+id/ModuleNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="18"
android:hint="#string/ModuleNumber"
android:inputType="numberSigned" />
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:text="#string/Del" />
<EditText
android:id="#+id/DocDate"
android:layout_width="158dp"
android:layout_height="wrap_content"
android:ems="18"
android:focusable="false"
android:hint="#string/DocDate"
android:inputType="date" />
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:text="#string/Impianto" />
<Spinner
android:id="#+id/Impianto"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/SiteManager" />
<Spinner
android:id="#+id/SiteManager"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:entries="#array/SiteManagers" />
</TableRow>
<TableRow
android:id="#+id/tableRow5"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/LavoriAttivita" />
</TableRow>
<TableRow
android:id="#+id/tableRow7"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/editText4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textMultiLine" />
</TableRow>
<TableRow
android:id="#+id/tableRow6"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/AffidatiAllImpresa" />
</TableRow>
<TableRow
android:id="#+id/tableRow8"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/editText5"
android:layout_width="138dp"
android:layout_height="wrap_content"
android:ems="10" />
</TableRow>
<TableRow
android:id="#+id/tableRow9"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/SubappaltoDi"
android:visibility="visible" />
</TableRow>
<TableRow
android:id="#+id/tableRow10"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/editText6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10" />
</TableRow>
<TableRow
android:id="#+id/tableRow11"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/EsitoVitep" />
<RadioButton
android:id="#+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Si" />
<RadioButton
android:id="#+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="No" />
</TableRow>
</TableLayout>
</LinearLayout>
</FrameLayout>
Are your texts that should write in Textviews have space between words?
Sometimes developers use samples like aaaaaaaaaaaaaa for testing and forgot
to replace them with real sample datas.