I don't know why the keyboard is blocking the space where I can type. My guess is that it is a layout issue, since it kind of works when I have an action bar enabled, but I don't want the action bar. And yes I've tried going into manifest and put android:windowSoftInputMode="adjustPan"(also resize, stateAlwaysHidden). I looked at most of the forums relating to this problem. Also, to mention that the username is located in the bottom half of the app.
<EditText
android:id="#+id/username"
android:layout_width="250dp"
android:layout_height="48dp"
android:layout_marginBottom="8dp"
android:alpha="0.65"
android:background="#drawable/sign_in_button"
android:ems="10"
android:enabled="false"
android:hint="#string/username"
android:inputType="textPersonName"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:textAlignment="textStart"
android:textColor="#color/buttonTextColor"
android:textColorHint="#color/buttonTextColor"
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="#+id/createAccount"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<EditText
android:id="#+id/password"
android:layout_width="250dp"
android:layout_height="48dp"
android:layout_marginBottom="9dp"
android:alpha="0.65"
android:background="#drawable/sign_in_button"
android:ems="10"
android:enabled="false"
android:hint="#string/password"
android:inputType="textPassword"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:textAlignment="textStart"
android:textColor="#color/buttonTextColor"
android:textColorHint="#color/buttonTextColor"
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="#+id/terms"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/goBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
android:textColor="#color/buttonTextColor"
android:visibility="invisible"
android:text="#string/goBack"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:layout_editor_absoluteY="0dp" />
<TextView
android:id="#+id/appTitle"
android:layout_width="211dp"
android:layout_height="wrap_content"
android:alpha="0.65"
android:fontFamily="cursive"
android:text="#string/app_name"
android:textAlignment="center"
android:textColor="#color/appColor"
android:textSize="36sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/slogan"
app:layout_constraintHorizontal_bias="0.502"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<TextView
android:id="#+id/slogan"
android:layout_width="211dp"
android:layout_height="30dp"
android:text="#string/slogan"
android:textAlignment="center"
android:textColor="#color/buttonTextColor"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toTopOf="#+id/signIn"
android:layout_marginBottom="16dp"
tools:layout_editor_absoluteY="374dp" />
<TextView
android:id="#+id/terms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:text="#string/terms"
android:textColor="#color/buttonTextColor"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/createAccount" />
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_login);
getSupportActionBar().hide();
Put this attribute in your activity
<activity
android:windowSoftInputMode="adjustPan"
/>
If it doesn't work put this in onCreate() method after setContentView:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
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.
I'm trying to convert this layout made using table layout to a constraint layout.
The second column and the third column could be hidden.
The price should be aligned to right.
The header in the first column should aligned to the left.
It's an exercise to learn constraints better, but I'm failing
<?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:id="#+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:shrinkColumns="*"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
android:divider="?android:attr/dividerHorizontal"
android:showDividers="middle">
<TableRow android:layout_marginBottom="2dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:gravity="start"
android:text="Price"
android:textColor="#android:color/black"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_marginStart="10dp"
android:gravity="end"
android:text="-"
android:textColor="#android:color/black"
android:textSize="12sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_marginStart="10dp"
android:gravity="end"
android:text="-"
android:textColor="#android:color/black"
android:textSize="12sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="3"
android:layout_marginStart="10dp"
android:gravity="end"
android:text="2000$"
android:textColor="#android:color/black"
android:textSize="12sp" />
</TableRow>
<TableRow
android:layout_marginTop="2dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:gravity="start"
android:text="Price2\n(test)"
android:textColor="#android:color/black"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_marginStart="10dp"
android:gravity="end"
android:text="8000$"
android:textColor="#android:color/black"
android:textSize="12sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_marginStart="10dp"
android:gravity="end"
android:text="-5000$"
android:textColor="#android:color/black"
android:textSize="12sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="3"
android:layout_marginStart="10dp"
android:gravity="end"
android:text="3000"
android:textColor="#android:color/black"
android:textSize="12sp" />
</TableRow>
</TableLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
I have try different ways: barriers, flow, but I didn't get the goal.
I find it difficult to vertically align columns 2, 3 and 4 and at the same time align rows 1 and 2 horizontally
I think you are looking for Barriers to complete your exercise. You would set a barrier to the left of each column and constrain each column to the barrier to the right.
Here is an example of using ConstraintLayout in place of a TableLayout. It is complex enough that I think staying with TableLayout for its functionality is warranted. Here is the result followed by the code. The code has some comments that explain what is going on.
<!--
This LinearLayout is here just to provide a means to center the ConstraintLayout.
-->
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingTop="32dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!--
A barrier is set at the start of each column.
-->
<androidx.constraintlayout.widget.Barrier
android:id="#+id/barrier1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="start"
app:constraint_referenced_ids="r1c1,r2c1" />
<androidx.constraintlayout.widget.Barrier
android:id="#+id/barrier2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="start"
app:constraint_referenced_ids="r1c2,r2c2" />
<androidx.constraintlayout.widget.Barrier
android:id="#+id/barrier3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="start"
app:constraint_referenced_ids="r1c3,r2c3" />
<androidx.constraintlayout.widget.Barrier
android:id="#+id/barrier4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="start"
app:constraint_referenced_ids="r1c4,r2c4" />
<!--
Each cell is constrained horizontally to the barrier to the right and to its own barrier to
the left. app:layout_constraintWidth_min="wrap" is specified to stop the cells from collapsing.
This is a hack IMO but effective.
-->
<TextView
android:id="#+id/r1c1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:gravity="start"
android:text="Price"
android:textColor="#android:color/black"
android:textSize="12sp"
android:textStyle="bold"
app:layout_constraintEnd_toStartOf="#id/barrier2"
app:layout_constraintStart_toStartOf="#id/barrier1"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_min="wrap" />
<TextView
android:id="#+id/r2c1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:gravity="start"
android:text="Price2\n(test)"
android:textColor="#android:color/black"
android:textSize="12sp"
android:textStyle="bold"
app:layout_constraintEnd_toStartOf="#id/barrier2"
app:layout_constraintStart_toStartOf="#id/barrier1"
app:layout_constraintTop_toBottomOf="#id/divider"
app:layout_constraintWidth_min="wrap" />
<TextView
android:id="#+id/r1c2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:gravity="end"
android:text="-"
android:textColor="#android:color/black"
android:textSize="12sp"
android:visibility="visible"
app:layout_constraintEnd_toStartOf="#id/barrier3"
app:layout_constraintStart_toStartOf="#id/barrier2"
app:layout_constraintTop_toTopOf="#id/r1c1"
app:layout_constraintWidth_min="wrap" />
<TextView
android:id="#+id/r2c2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:gravity="end"
android:text="8000$"
android:textColor="#android:color/black"
android:textSize="12sp"
android:visibility="visible"
app:layout_constraintEnd_toStartOf="#id/barrier3"
app:layout_constraintStart_toStartOf="#id/barrier2"
app:layout_constraintTop_toBottomOf="#id/divider"
app:layout_constraintWidth_min="wrap" />
<TextView
android:id="#+id/r1c3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:gravity="end"
android:text="-"
android:textColor="#android:color/black"
android:textSize="12sp"
app:layout_constraintEnd_toStartOf="#id/barrier4"
app:layout_constraintStart_toStartOf="#id/barrier3"
app:layout_constraintTop_toTopOf="#id/r1c1"
app:layout_constraintWidth_min="wrap" />
<TextView
android:id="#+id/r2c3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:gravity="end"
android:text="-5000$"
android:textColor="#android:color/black"
android:textSize="12sp"
app:layout_constraintEnd_toStartOf="#id/barrier4"
app:layout_constraintStart_toStartOf="#id/barrier3"
app:layout_constraintTop_toBottomOf="#id/divider"
app:layout_constraintWidth_min="wrap" />
<TextView
android:id="#+id/r1c4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="end"
android:text="2000$"
android:textColor="#android:color/black"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="#id/r1c1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="#id/barrier4"
app:layout_constraintWidth_min="wrap" />
<TextView
android:id="#+id/r2c4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="end"
android:text="3000"
android:textColor="#android:color/black"
android:textSize="12sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="#id/barrier4"
app:layout_constraintTop_toBottomOf="#id/divider"
app:layout_constraintWidth_min="wrap" />
<View
android:id="#+id/divider"
android:layout_width="0dp"
android:layout_height="1dp"
android:background="#android:color/black"
app:layout_constraintEnd_toEndOf="#id/r1c4"
app:layout_constraintStart_toStartOf="#id/r1c1"
app:layout_constraintTop_toBottomOf="#id/r1c1" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.appcompat.widget.LinearLayoutCompat>
TableLayout will make the width of each cell in a column the width of the widest cell content. This is tricky to do with ConstraintLayout and is accomplished by setting the width of each cell to 0dp and constraining the start and end to the barriers that bracket the column. See this Stack Overflow question for an explanation. I consider this a hack, but it works.
The other difference between this implementation and TableLayout is how the table behaves when a single cell is collapsed. TableLayout will shift the remaining cells over while this implementation will maintain the original columns. If all the cells in a column are collapsed (made gone) then this works the same as TableLayout.
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:
The button is the blue square
I'm adding GridLayout in a layout file of the project. After that, if I add anything in the layout it goes to the corner and when I'm testing everything is in place!
<TextView
android:id="#+id/sumTxtView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="31+12"
android:textColor="#android:color/background_dark"
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/startButton"
app:layout_constraintEnd_toStartOf="#+id/pointsTxtView"
app:layout_constraintHorizontal_bias="0.487"
app:layout_constraintStart_toEndOf="#+id/timerTxtView"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.103" />
<android.support.v7.widget.GridLayout
android:id="#+id/theGridLayout"
android:layout_width="323dp"
android:layout_height="441dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.523"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0">
<Button
android:id="#+id/button3"
android:layout_width="82dp"
android:layout_height="45dp"
app:layout_column="3"
app:layout_row="3" />
</android.support.v7.widget.GridLayout>
Any idea what is happening?
Thanks
I am pretty new to Android Studio, so please forgive any thing which may have been obvious but I did not pick up.
I would like help in the below situation -
I have setup two layouts:
Relative Layout & a Constraint Layout (which is nested in ScrollView).
I wanted to keep some views to be visible all the time, so I put them in a Relative Layout. I put all other views in a constraint layout which is scrollable, since the number of elements do not fit in the screen.
I am trying to get the same effect which you get when you freeze the top row of an excel worksheet.
I tried to adjust the layout height property of the Constraint Layout but I can't seem to get it right. What I want is to anchor my Constraint Layout below the Relative Layout.
I have attached my code.
Thanks a lot in advance,
Regards,
Ravi.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/relative_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.android.raviagl.netlandingcostcalculate.MainActivity">
<TextView
android:id="#+id/sap"
android:layout_width="120dp"
android:layout_height="72dp"
android:layout_marginLeft="16dp"
android:layout_toRightOf="#id/nlc"
android:gravity="center_vertical"
android:text="SAP"
android:textColor="#color/colorPrimaryDark"
android:textSize="20sp" />
<Button
android:id="#+id/reset_all"
android:layout_width="120dp"
android:layout_height="72dp"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="13dp"
android:text="Reset" />
<TextView
android:id="#+id/nlc"
android:layout_width="120dp"
android:layout_height="72dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="8dp"
android:gravity="center_vertical"
android:text="NLC"
android:textColor="#color/colorPrimaryDark"
android:textSize="20sp" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.constraint.ConstraintLayout
android:id="#+id/constraint_layout_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:layout_editor_absoluteY="81dp">
<EditText
android:id="#+id/dp"
android:layout_width="175dp"
android:layout_height="40dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="88dp"
android:ems="10"
android:gravity="right"
android:inputType="number"
android:textColor="#color/colorPrimaryDark"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="#+id/allowance"
android:layout_width="175dp"
android:layout_height="40dp"
android:layout_marginRight="16dp"
android:ems="10"
android:gravity="right"
android:inputType="number"
android:textColor="#color/colorPrimaryDark"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/dp" />
<EditText
android:id="#+id/gst"
android:layout_width="175dp"
android:layout_height="40dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:ems="10"
android:gravity="right"
android:inputType="number"
android:textColor="#color/colorPrimaryDark"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/allowance" />
<EditText
android:id="#+id/slab"
android:layout_width="175dp"
android:layout_height="40dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:ems="10"
android:gravity="right"
android:inputType="number"
android:textColor="#color/colorPrimaryDark"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/gst" />
<RadioGroup
android:id="#+id/slab_radio_group"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/slab">
<RadioButton
android:id="#+id/radio_slab_value"
android:layout_width="170dp"
android:layout_height="31dp"
android:layout_marginRight="16dp"
android:layout_weight="1"
android:checked="true"
android:text="Use Fixed Amount"
android:textColor="#color/colorPrimaryDark"
android:textSize="14sp"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteY="248dp" />
<RadioButton
android:id="#+id/radio_slab_percent"
android:layout_width="170dp"
android:layout_height="31dp"
android:layout_marginRight="16dp"
android:layout_weight="1"
android:text="Use SAP Percent"
android:textColor="#color/colorPrimaryDark"
android:textSize="14sp"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteY="248dp" />
</RadioGroup>
<EditText
android:id="#+id/sell_through"
android:layout_width="175dp"
android:layout_height="40dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="48dp"
android:ems="10"
android:gravity="right"
android:inputType="number"
android:textColor="#color/colorPrimaryDark"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/slab" />
<EditText
android:id="#+id/sell_out"
android:layout_width="175dp"
android:layout_height="40dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:ems="10"
android:gravity="right"
android:inputType="number"
android:textColor="#color/colorPrimaryDark"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/sell_through" />
<EditText
android:id="#+id/display"
android:layout_width="175dp"
android:layout_height="40dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:ems="10"
android:gravity="right"
android:inputType="number"
android:textColor="#color/colorPrimaryDark"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/sell_out" />
<RadioGroup
android:id="#+id/display_radio_group"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/display">
<RadioButton
android:id="#+id/radio_display_value"
android:layout_width="170dp"
android:layout_height="31dp"
android:layout_marginRight="16dp"
android:layout_weight="1"
android:checked="true"
android:text="Use Fixed Amount"
android:textColor="#color/colorPrimaryDark"
android:textSize="14sp"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteY="248dp" />
<RadioButton
android:id="#+id/radio_display_percent"
android:layout_width="170dp"
android:layout_height="31dp"
android:layout_marginRight="16dp"
android:layout_weight="1"
android:text="Use SAP Percent"
android:textColor="#color/colorPrimaryDark"
android:textSize="14sp"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteY="248dp" />
</RadioGroup>
<EditText
android:id="#+id/tie_up"
android:layout_width="175dp"
android:layout_height="40dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="48dp"
android:ems="10"
android:gravity="right"
android:inputType="number"
android:textColor="#color/colorPrimaryDark"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/display" />
<EditText
android:id="#+id/handling"
android:layout_width="175dp"
android:layout_height="40dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:ems="10"
android:gravity="right"
android:inputType="number"
android:textColor="#color/colorPrimaryDark"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tie_up" />
<EditText
android:id="#+id/cash_discount"
android:layout_width="175dp"
android:layout_height="40dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:ems="10"
android:gravity="right"
android:inputType="number"
android:textColor="#color/colorPrimaryDark"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/handling" />
<TextView
android:id="#+id/d_dp"
android:layout_width="175dp"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginStart="8dp"
android:text="DP"
android:textColor="#color/colorPrimaryDark"
android:textSize="18sp"
app:layout_constraintBaseline_toBaselineOf="#+id/dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/d_allowance"
android:layout_width="175dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="Allowance"
android:textColor="#color/colorPrimaryDark"
android:textSize="18sp"
app:layout_constraintBaseline_toBaselineOf="#+id/allowance"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/d_gst"
android:layout_width="175dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="GST"
android:textColor="#color/colorPrimaryDark"
android:textSize="18sp"
app:layout_constraintBaseline_toBaselineOf="#+id/gst"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/d_slab"
android:layout_width="175dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="Slab"
android:textColor="#color/colorPrimaryDark"
android:textSize="18sp"
app:layout_constraintBaseline_toBaselineOf="#+id/slab"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/d_sell_through"
android:layout_width="175dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="Sell Through"
android:textColor="#color/colorPrimaryDark"
android:textSize="18sp"
app:layout_constraintBaseline_toBaselineOf="#+id/sell_through"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/d_sell_out"
android:layout_width="175dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="Sell Out"
android:textColor="#color/colorPrimaryDark"
android:textSize="18sp"
app:layout_constraintBaseline_toBaselineOf="#+id/sell_out"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/d_display"
android:layout_width="175dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="Display"
android:textColor="#color/colorPrimaryDark"
android:textSize="18sp"
app:layout_constraintBaseline_toBaselineOf="#+id/display"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/d_tie_up"
android:layout_width="175dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="Tie UP"
android:textColor="#color/colorPrimaryDark"
android:textSize="18sp"
app:layout_constraintBaseline_toBaselineOf="#+id/tie_up"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/d_handling"
android:layout_width="175dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="Handling"
android:textColor="#color/colorPrimaryDark"
android:textSize="18sp"
app:layout_constraintBaseline_toBaselineOf="#+id/handling"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/d_cash_discount"
android:layout_width="175dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="Cash Discount"
android:textColor="#color/colorPrimaryDark"
android:textSize="18sp"
app:layout_constraintBaseline_toBaselineOf="#+id/cash_discount"
app:layout_constraintStart_toStartOf="parent" />
</android.support.constraint.ConstraintLayout>
</ScrollView>
</RelativeLayout>
There are a few options to consider here but I think the one that requires the least amount of refactoring your layout is this:
Add android:layout_below attribute to your ScrollView and position it under one the views that are fixed. It doesn't matter which one as long as they are the same height:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/sap">
Decrease (or remove) the top margin from the EditText with the ID android:id="#+id/dp"to eliminate unnecessary space on the top.
All that being said since you are using fixed widths for all the views in your layout you might run into some problems with displaying it on different screen sizes. For example the three fixed views on the top might overlap each other if there is not enough horizontal space. This could possibly be resolved by using other layouts (such as ConstraintLayout or LinearLayout) as root and/or not using fixed widths. However, this would require much more refactoring that the solution above.