layout - How to make ConstraintLayout scrollable in android? -


i trying dynamically add elements constraintlayout such scrollable. wrapped constraintlayout in scrollview. looks nice before elements inserted. however, after insertions, scrollview not expand elements @ bottom not shown.

https://i.imgur.com/ptnd5uo.png buttons disapear

<scrollview 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="wrap_content"     android:fillviewport="true"     tools:context="com.example.abel.standingcalculator.mainactivity"> <android.support.constraint.constraintlayout     android:id="@+id/activity_main"     android:layout_width="match_parent"     android:layout_height="wrap_content"     tools:layout_editor_absolutex="0dp"     tools:layout_editor_absolutey="0dp">      <button         android:id="@+id/calculate"         android:layout_width="122dp"         android:layout_height="48dp"         android:layout_marginbottom="0dp"         android:layout_weight="1"         android:text="calculate"         app:layout_constraintbottom_tobottomof="@+id/save"         app:layout_constraintleft_torightof="@+id/save"         app:layout_constraintright_torightof="parent" />      <button         android:id="@+id/save"         android:layout_width="125dp"         android:layout_height="49dp"         android:layout_marginbottom="0dp"         android:layout_margintop="40dp"         android:layout_weight="1"         android:text="save"         app:layout_constraintbottom_tobottomof="parent"         app:layout_constraintleft_toleftof="parent"         app:layout_constraintright_toleftof="@+id/calculate"         app:layout_constrainttop_tobottomof="@+id/new_item"         app:layout_constraintvertical_bias="0.325" />      <edittext         android:id="@+id/proportion1"         android:layout_width="0dp"         android:layout_height="36dp"         android:layout_marginbottom="0dp"         android:layout_marginend="8dp"         android:layout_marginleft="8dp"         android:layout_marginright="8dp"         android:ems="10"         android:inputtype="numberdecimal"         android:textsize="14sp"         android:visibility="visible"         app:layout_constraintbottom_tobottomof="@+id/proportion_label1"         app:layout_constrainthorizontal_bias="0.0"         app:layout_constraintleft_toleftof="@+id/item_name1"         app:layout_constraintright_torightof="parent" />      <edittext         android:id="@+id/sd1"         android:layout_width="0dp"         android:layout_height="36dp"         android:ems="10"         android:inputtype="numberdecimal"         android:textsize="14sp"         android:visibility="visible"         app:layout_constraintbottom_tobottomof="@+id/sd_label1"         app:layout_constrainthorizontal_bias="0.0"         app:layout_constraintleft_toleftof="@+id/proportion1"         app:layout_constraintright_torightof="parent" />      <edittext         android:id="@+id/mean1"         android:layout_width="0dp"         android:layout_height="36dp"         android:ems="10"         android:inputtype="numberdecimal"         android:textalignment="center"         android:textsize="14sp"         app:layout_constraintbottom_tobottomof="@+id/mean_label1"         app:layout_constrainthorizontal_bias="0.0"         app:layout_constraintleft_toleftof="@+id/sd1"         app:layout_constraintright_torightof="parent" />      <edittext         android:id="@+id/total_grade1"         android:layout_width="0dp"         android:layout_height="36dp"         android:layout_marginbottom="1dp"         android:ems="10"         android:inputtype="numberdecimal"         android:textalignment="center"         android:textappearance="@style/textappearance.appcompat.medium"         android:textcolor="@android:color/black"         android:textsize="14sp"         app:layout_constraintbottom_tobottomof="@+id/total_grade_label1"         app:layout_constrainthorizontal_bias="0.0"         app:layout_constraintleft_toleftof="@+id/mean1"         app:layout_constraintright_torightof="parent" />      <textview         android:id="@+id/item_name_label1"         android:layout_width="41dp"         android:layout_height="wrap_content"         android:layout_marginleft="20dp"         android:layout_marginstart="16dp"         android:layout_margintop="30dp"         android:text="item name"         app:layout_constraintleft_toleftof="parent"         app:layout_constrainttop_totopof="parent" />      <textview         android:id="@+id/proportion_label1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_marginleft="16dp"         android:layout_marginstart="16dp"         android:layout_margintop="20dp"         android:text="proportion"         app:layout_constraintleft_toleftof="parent"         app:layout_constrainttop_tobottomof="@+id/item_name_label1" />      <textview         android:id="@+id/sd_label1"         android:layout_width="60dp"         android:layout_height="wrap_content"         android:layout_marginleft="16dp"         android:layout_margintop="20dp"         android:text="standard deviation"         app:layout_constraintleft_toleftof="parent"         app:layout_constrainttop_tobottomof="@+id/proportion_label1" />      <textview         android:id="@+id/mean_label1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_marginleft="16dp"         android:layout_marginstart="16dp"         android:layout_margintop="20dp"         android:text="mean"         app:layout_constraintleft_toleftof="parent"         app:layout_constrainttop_tobottomof="@+id/sd_label1" />      <textview         android:id="@+id/total_grade_label1"         android:layout_width="46dp"         android:layout_height="wrap_content"         android:layout_marginleft="16dp"         android:layout_margintop="20dp"         android:text="total grade"         app:layout_constraintleft_toleftof="parent"         app:layout_constrainttop_tobottomof="@+id/mean_label1" />      <textview         android:id="@+id/your_grade_label1"         android:layout_width="40dp"         android:layout_height="wrap_content"         android:layout_marginleft="16dp"         android:layout_marginstart="16dp"         android:layout_margintop="20dp"         android:text="your grade"         app:layout_constraintleft_toleftof="parent"         app:layout_constrainttop_tobottomof="@+id/total_grade_label1" />      <edittext         android:id="@+id/item_name1"         android:layout_width="0dp"         android:layout_height="36dp"         android:layout_marginend="8dp"         android:layout_marginleft="32dp"         android:layout_marginright="8dp"         android:layout_marginstart="32dp"         android:ems="10"         android:inputtype="text"         android:textalignment="center"         android:textsize="14sp"         android:visibility="visible"         app:layout_constraintbottom_tobottomof="@+id/item_name_label1"         app:layout_constrainthorizontal_bias="0.0"         app:layout_constraintleft_torightof="@+id/item_name_label1"         app:layout_constraintright_torightof="parent" />      <button         android:id="@+id/new_item"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_marginleft="8dp"         android:layout_marginright="8dp"         android:layout_margintop="38dp"         android:text="add new item"         app:layout_constrainthorizontal_bias="0.97"         app:layout_constraintleft_toleftof="parent"         app:layout_constraintright_torightof="parent"         app:layout_constrainttop_tobottomof="@+id/your_grade_label1" />      <edittext         android:id="@+id/your_grade1"         android:layout_width="323dp"         android:layout_height="36dp"         android:ems="10"         android:inputtype="numberdecimal"         android:textalignment="center"         android:textappearance="@style/textappearance.appcompat.medium"         android:textcolor="@android:color/black"         android:textsize="14sp"         app:layout_constraintbottom_tobottomof="@+id/your_grade_label1"         app:layout_constrainthorizontal_bias="0.0"         app:layout_constraintleft_toleftof="@+id/total_grade1"         app:layout_constraintright_torightof="parent" />      <android.support.constraint.guideline         android:id="@+id/guideline"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:orientation="vertical"         app:layout_constraintguide_begin="16dp"         tools:layout_editor_absolutex="16dp"         tools:layout_editor_absolutey="81dp" />     <android.support.constraint.constraintlayout         android:id="@+id/activity_main"         android:layout_width="match_parent"         android:layout_height="wrap_content">     </android.support.constraint.constraintlayout> </scrollview> 

edit: here dynamically added part.

    mconstraintset.clone(mconstraintlayout); // constraints constraintset        }     //item name label     mconstraintset.constrainheight(item_name_label.getid(),             constraintset.wrap_content);     mconstraintset.constrainwidth(item_name_label.getid(),             todp(41));     int your_grade_id = (itemcount == 2) ? r.id.your_grade1 : ids.get("your_grade"+(itemcount-1));     mconstraintset.connect(item_name_label.getid(), constraintset.top, your_grade_id,             constraintset.bottom,todp(40));     mconstraintset.connect(item_name_label.getid(), constraintset.start, constraintset.parent_id,             constraintset.start,todp(20));     //for item name     mconstraintset.constrainheight(item_name.getid(),             todp(36));     mconstraintset.constrainwidth(item_name.getid(),             0);     mconstraintset.connect(item_name.getid(), constraintset.bottom, item_name_label.getid(),             constraintset.bottom,0);     mconstraintset.connect(item_name.getid(), constraintset.start, item_name_label.getid(),             constraintset.end, todp(32));     mconstraintset.connect(item_name.getid(), constraintset.end, constraintset.parent_id,             constraintset.end,0);     //proportion     mconstraintset.constrainheight(proportion_label.getid(),             constraintset.wrap_content);     mconstraintset.constrainwidth(proportion_label.getid(),             constraintset.wrap_content);     mconstraintset.connect(proportion_label.getid(), constraintset.top, item_name_label.getid(),             constraintset.bottom,todp(20));     mconstraintset.connect(proportion_label.getid(), constraintset.start, item_name_label.getid(),             constraintset.start,0);     connect(mconstraintset, proportion, item_name, proportion_label);     //sd     mconstraintset.constrainheight(sd_label.getid(),             constraintset.wrap_content);     mconstraintset.constrainwidth(sd_label.getid(),             todp(60));     mconstraintset.connect(sd_label.getid(), constraintset.top, proportion_label.getid(),             constraintset.bottom,todp(20));     mconstraintset.connect(sd_label.getid(), constraintset.start, proportion_label.getid(),             constraintset.start,0);     connect(mconstraintset, sd, proportion, sd_label);     //mean     mconstraintset.constrainheight(mean_label.getid(),             constraintset.wrap_content);     mconstraintset.constrainwidth(mean_label.getid(),             constraintset.wrap_content);     mconstraintset.connect(mean_label.getid(), constraintset.top, sd_label.getid(),             constraintset.bottom,todp(20));     mconstraintset.connect(mean_label.getid(), constraintset.start, sd_label.getid(),             constraintset.start,0);     connect(mconstraintset, mean, sd, mean_label);     //total grade     mconstraintset.constrainheight(total_grade_label.getid(),             constraintset.wrap_content);     mconstraintset.constrainwidth(total_grade_label.getid(),             todp(46));     mconstraintset.connect(total_grade_label.getid(), constraintset.top, mean_label.getid(),             constraintset.bottom,todp(20));     mconstraintset.connect(total_grade_label.getid(), constraintset.start, mean_label.getid(),             constraintset.start,0);     connect(mconstraintset, total_grade, mean, total_grade_label);     //your grade     mconstraintset.constrainheight(your_grade_label.getid(),             constraintset.wrap_content);     mconstraintset.constrainwidth(your_grade_label.getid(),             todp(40));     mconstraintset.connect(your_grade_label.getid(), constraintset.top, total_grade_label.getid(),             constraintset.bottom,todp(20));     mconstraintset.connect(your_grade_label.getid(), constraintset.start, total_grade_label.getid(),             constraintset.start,0);     connect(mconstraintset, your_grade, total_grade, your_grade_label);     //relocate buttons     mconstraintset.connect(r.id.new_item, constraintset.top, your_grade_label.getid(),             constraintset.bottom,todp(40));     mconstraintset.connect(r.id.save, constraintset.top, r.id.new_item,             constraintset.bottom,todp(40));     mconstraintset.connect(r.id.save, constraintset.bottom, constraintset.parent_id,             constraintset.bottom,todp(0));      mconstraintset.applyto(mconstraintlayout); 

hopefully make code more readable. https://i.imgur.com/lyixlvi.png

try set height=0dp code below....

<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"> <scrollview  android:layout_width="0dp"  android:layout_height="0dp"  app:layout_constraintleft_toleftof="parent"  app:layout_constraintright_torightof="parent"  app:layout_constrainttop_totopof="parent"  android:layout_marginbottom="0dp"  app:layout_constraintbottom_totopof="@+id/btndone">   <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">        <textview         android:id="@+id/tvtest"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         tools:text="testtt" />  </android.support.constraint.constraintlayout> </scrollview> </android.support.constraint.constraintlayout> 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -