Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Align FrameLayout inside ConstraintLayout to bottom

Tags:

I want a layout above recycler view at the bottom of the screen,(like a frame) so that even when that layout is visible I can still scroll recycler view behind it. So I want to align the frame layout at the bottom of the screen and make it visible and invisible as per requirement. Here is my code.

 <?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"     tools:context="com.protossoft.root.aesencryption.MainActivity">        <ListView         android:layout_width="match_parent"         android:id="@+id/listView"         android:layout_height="match_parent">      </ListView>    <!--  <RelativeLayout         android:layout_width="match_parent"          android:layout_height="wrap_content">-->     <FrameLayout         android:layout_width="match_parent"          android:layout_height="wrap_content"         tools:layout_editor_absoluteX="0dp"         tools:layout_editor_absoluteY="443dp">          <LinearLayout             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:layout_margin="10dp"             android:gravity="center"             android:orientation="horizontal">              <ImageView                 android:id="@+id/deviceNumberImage"                 android:layout_width="0dp"                 android:layout_height="wrap_content"                 android:layout_weight="0.2"                 android:src="@android:drawable/btn_default" />              <TextView                 android:id="@+id/deviceNumber"                 android:layout_width="0dp"                 android:layout_height="wrap_content"                 android:layout_weight="0.8"                 android:text="990000862471854" />          </LinearLayout>     </FrameLayout>    <!-- </RelativeLayout>--> 

I don't have too much of idea about constraint layout, but when I am moving the view at the bottom from the editor, it is using property like

tools:layout_editor_absoluteX="0dp"     tools:layout_editor_absoluteY="443dp" 

I want to achieve the same with some property like align_parentBottom. But none of the properties is available for use. What do I need to do so that the frame layout is visible at the bottom and on the top of recycler view at the same time? Thanks :)

like image 349
Pritish Avatar asked Dec 05 '17 11:12

Pritish


People also ask

Can we use RelativeLayout inside ConstraintLayout?

Constraints define the relation between two different view elements, and chains can be used dictate the spacing between them. In addition, guidelines can be used to create percentage-based layouts. Most of what can be achieved in LinearLayout and RelativeLayout can be done in ConstraintLayout.

How do I fix the bottom layout on my Android?

You can set the layout_height="0dp" of your header, footer and ScrollView and define a layout_weight . Just play around with the values until you find out which works best. The resulting heights of header and footer would dynamically change with the screensize.

How do I set TextView in bottom of ConstraintLayout?

layout_constraintBottom_toTopOf —> Align the bottom of the desired view to the top of another. layout_constraintTop_toBottomOf —> Align the top of the desired view to the bottom of another. It will be good approach if you use ScrollView ( Where child is TextView).


1 Answers

I want to achieve the same with some property like align_parentBottom.

You should use app:layout_constraintBottom_toBottomOf="parent" attribute.

Here's the setup that you need:

<?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">      <FrameLayout         android:layout_width="0dp"         android:layout_height="wrap_content"         app:layout_constraintBottom_toBottomOf="parent"         app:layout_constraintEnd_toEndOf="parent"         app:layout_constraintStart_toStartOf="parent">         ...     </FrameLayout>  </android.support.constraint.ConstraintLayout> 
like image 199
azizbekian Avatar answered Oct 07 '22 20:10

azizbekian