Android percent screen width in RecyclerView item

You can override one of the LayoutManager methods used by your RecyclerView to force specific size: recyclerView.setLayoutManager(new LinearLayoutManager(this){ @Override public boolean checkLayoutParams(RecyclerView.LayoutParams lp) { // force height of viewHolder here, this will override layout_height from xml lp.height = getHeight() / 3; return true; } }); This is assuming your RecyclerView fits the screen. If you … Read more

Scrollview inside constraint layout does not scroll to the bottom of the parent constraint

This layout works in my app. The trick is to set these two attributes in ScrollView: android:layout_height=”0dp” app:layout_constraintBottom_toBottomOf=”parent” The simplified layout from my app: <?xml version=”1.0″ encoding=”utf-8″?> <android.support.constraint.ConstraintLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:app=”http://schemas.android.com/apk/res-auto” xmlns:tools=”http://schemas.android.com/tools” android:layout_width=”match_parent” android:layout_height=”match_parent” android:theme=”@style/ThemeOverlay.AppCompat.Light”> <RelativeLayout android:id=”@+id/linear” android:layout_width=”0dp” android:layout_height=”56dp” android:background=”@color/title” app:layout_constraintLeft_toLeftOf=”parent” app:layout_constraintRight_toRightOf=”parent” app:layout_constraintTop_toTopOf=”parent” /> <ScrollView android:layout_width=”0dp” android:layout_height=”0dp” app:layout_constraintBottom_toBottomOf=”parent” app:layout_constraintLeft_toLeftOf=”parent” app:layout_constraintRight_toRightOf=”parent” app:layout_constraintTop_toBottomOf=”@id/linear”> <android.support.constraint.ConstraintLayout android:layout_width=”match_parent” android:layout_height=”wrap_content”> <TextView android:id=”@+id/titleView” … Read more

Android add other layout in ConstraintLayout using include tag

Android include tag does work with ConstraintLayout, but you need to declare how big is the layout you want to include with the following attributes. <include layout=”@layout/content_main” android:layout_width=”100dp” android:layout_height=”250dp” …/> For included layout having dynamic height use wrap_content as a value in layout_height or layout_width attributes of include tag. <include android:id=”@+id/input_include” layout=”@layout/task_input” android:layout_width=”match_parent” android:layout_height=”wrap_content”/> After … Read more

ConstraintLayout Chains and Text Ellipsis + Image on the Right

UPDATE JULY 2020: What does constrainedWidth/Height do? A lot of people kept asking me what exactly does this constrainedWidth/Height do when set to true (defaults to false). I finally have an answer (from a Google employee), so in lieu of clearing up all the doubts people coming to this post keep having, here’s what I … Read more

Android : How to programmatically set layout_constraintRight_toRightOf “parent”

Here is an example of setting a button to the bottom of parent view using java code: ConstraintLayout constraintLayout; ConstraintSet constraintSet; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); constraintLayout = (ConstraintLayout) findViewById(R.id.activity_main_constraint_layout); Button button = new Button(this); button.setText(“Hello”); constraintLayout.addView(button); constraintSet = new ConstraintSet(); constraintSet.clone(constraintLayout); constraintSet.connect(button.getId(), ConstraintSet.LEFT, constraintLayout.getId(), ConstraintSet.RIGHT, 0); constraintSet.constrainDefaultHeight(button.getId(), 200); constraintSet.applyTo(constraintLayout); } to … Read more

ConstraintLayout vs Coordinator layout?

CoordinatorLayout is a super-powered FrameLayout. CoordinatorLayout CoordinatorLayout is intended for two primary use cases: As a top-level application decor or chrome layout As a container for a specific interaction with one or more child views By default, if you add multiple children to a FrameLayout, they would overlap each other. A FrameLayout should be used … Read more

Change Guideline percentage in constraint layout programmatically

There is two ways to do it: Using ConstraintLayout.LayoutParams This method get a specific parameter from the ConstraintLayout and modify it. Guideline guideLine = (Guideline) findViewById(R.id.your_guideline); ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) guideLine.getLayoutParams(); params.guidePercent = 0.45f; // 45% // range: 0 <-> 1 guideLine.setLayoutParams(params); Using ConstraintSet This method consists in cloning the ConstraintLayout attributes, modifying them and … Read more

ConstraintLayout, when constraint dependent view is gone, the layout view behave weirdly

Try following. Set the first view’s left and top constraints to “parent”. After that: set the txt_body textview width to “0dp” set the left constraint to the first view’s right side set the right constraint to the tail view’s left side. So, whenever you set the first view’s visibility to “gone”, the body view will … Read more

Removing/Adding constraint programmatically in ConstraintLayout

I have not worked through your code, but the following illustrates how to break and make the constraint using ConstraintSet. ConstraintSet set = new ConstraintSet(); ConstraintLayout layout; layout = (ConstraintLayout) findViewById(R.id.layout); set.clone(layout); // The following breaks the connection. set.clear(R.id.bottomText, ConstraintSet.TOP); // Comment out line above and uncomment line below to make the connection. // set.connect(R.id.bottomText, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)