Textview width is not the fit the width of the parent - width

I couldn't make equal width of Textview and linearlayout. Although I set width match_parent in Textview it doesn't fit with the parent width.
I saw these posts :
Android textView width not increasing
Android TextView does not expand to match parent
TextView width match drawableTop width
How to adjust text font size to fit textview
How to adjust text font size to fit textview
But my problem isn't resolved
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right|center_vertical"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:orientation="horizontal">
<ImageView
android:id="#+id/thumbnail"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:src="#drawable/defaultpicpic" />
<TextView
android:id="#+id/title"
style="#style/textViewItemStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingTop="10dp" />
</LinearLayout>

I resolved my problem by wrapping the views in a LinearLayout and followed by a small View beneath.
It is not clear why this worked.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:attr/selectableItemBackground"
android:gravity="right|center_vertical"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="right|center_vertical"
android:orientation="horizontal">
<ImageView
android:id="#+id/thumbnail"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:src="#drawable/thumb" />
<TextView
android:id="#+id/title"
style="#style/textViewItemStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="2px" />
</LinearLayout>

Related

How to position ViewPager above RecyclerView?

This xml layout has been populated by ViewPager and RecyclerView via an activity class, I want to position ViewPager on top and RecyclerView at the bottom, I tired to use android:layout_below="#+id/awesomepager" in the LinearLayout of RecyclerView but it doesn't work (it stays on top behind the toolbar[Deep blue color in the picture]), I also used android:layout_alignBottom="#+id/awesomepager" but that puts it inside the ViewPager at the bottom.
I basically want ViewPager and RecyclerView to be siblings , like this picture , black area to be ViewPager at the top and the green area to be RecyclerView at the bottom.
what is correct way to do this?
viewpager_with_toolbar_overlay.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ProgressBar
android:id="#+id/progressbar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.v4.view.ViewPager
android:id="#+id/awesomepager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="#068006"
android:layout_below="#+id/awesomepager"
>
<android.support.v7.widget.RecyclerView
android:id="#+id/episodesLIST"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:scrollbars="horizontal" />
</LinearLayout>
</RelativeLayout>
<include layout="#layout/toolbar_layout" />
</FrameLayout>
Update:
If I define the hight of ViewPager the problem will be resolved , but when screen size changes lower part of the screen will be blank
I searched a lot and finally came up with a solution, first I changed RelativeLayout to LinearLayout and added android:orientation="vertical" to it, then added android:layout_weight="1" to ViewPager.
Final version
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ProgressBar
android:id="#+id/progressbar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<android.support.v4.view.ViewPager
android:id="#+id/awesomepager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="#068006"
android:layout_below="#+id/awesomepager"
>
<android.support.v7.widget.RecyclerView
android:id="#+id/episodesLIST"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:scrollbars="horizontal" />
</LinearLayout>
</LinearLayout>
<include layout="#layout/toolbar_layout" />
</FrameLayout>

BottomSheet move to top of screen when changing visibility of its component

I have a bottom sheet with a NestedScrollView inside (see below). When I press on a FAB button, I want to make some parts in this NestedScrollView invisible. But when I change some linearlayouts visibilities to GONE, bottomsheet fly aways from the top.
My XML code:
<?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:id="#+id/messageOptionBottomSheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/back_miscellaneous"
android:gravity="center"
android:orientation="vertical"
app:behavior_peekHeight="0dp"
app:layout_behavior="#string/bottom_sheet_behavior">
<View
android:id="#+id/divider2"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/textSecondary" />
<LinearLayout
android:id="#+id/layoutDeleteMessage"
android:layout_width="match_parent"
android:layout_height="#dimen/_35sdp"
android:layout_margin="#dimen/_10sdp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:animateLayoutChanges="true"
tools:ignore="UseCompoundDrawables">
<ImageView
android:layout_width="#dimen/_22sdp"
android:layout_height="#dimen/_22sdp"
android:contentDescription="#string/app_name"
android:src="#drawable/ic_remove" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/_10sdp"
android:fontFamily="#font/ubuntu_medium"
android:includeFontPadding="false"
android:text="#string/delete_message"
android:textColor="#color/textSecondary"
android:textSize="#dimen/_12ssp" />
<TextView
android:id="#+id/textConfirmDelete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="#dimen/_10sdp"
android:fontFamily="#font/ubuntu_medium"
android:gravity="end"
android:includeFontPadding="false"
android:text="#string/confirm"
android:textColor="#color/red"
android:textSize="#dimen/_12ssp"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
Your bottom sheet is moving top because you are using
android:animateLayoutChanges="true"
remove this line from your layoutDeleteMessage (Linear layout)
Hope this solve your problem

Motionlayout with recyclerView is Shaky

I used a recycler view in my motion-layout with a handle which is an ImageView.But the first time you want to swipe it up it shakes and goes down and up and doesn't come up.
I tried to play with the attributes but nothing worked.
layout:
<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:id="#+id/root">
<androidx.constraintlayout.motion.widget.MotionLayout
android:id="#+id/motionLayout"
app:layoutDescription="#xml/scene3"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:showPaths="true">
<ImageView
android:id="#+id/image"
android:src="#drawable/ic_launcher_background"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="#id/testId" />
<RelativeLayout
android:id="#+id/testId"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintVertical_chainStyle="spread">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_media_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/media_send_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_margin="16dp"
android:onClick="sendTheMessages"
app:fabSize="normal" />
</RelativeLayout>
</androidx.constraintlayout.motion.widget.MotionLayout>
</RelativeLayout>
scene3.xml:
<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:motion="http://schemas.android.com/apk/res-auto">
<Transition
motion:constraintSetEnd="#+id/end"
motion:constraintSetStart="#+id/start"
motion:duration="300"
motion:interpolator="linear">
<OnSwipe
motion:touchAnchorId="#+id/image"
motion:touchAnchorSide="bottom"
motion:dragDirection="dragUp"
motion:dragScale="5"
motion:maxVelocity="5000"
motion:moveWhenScrollAtTop="true" />
</Transition>
<ConstraintSet android:id="#+id/start">
<Constraint
android:id="#+id/testId"
android:layout_width="match_parent"
android:layout_height="0dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintTop_toBottomOf="parent"
motion:layout_constraintVertical_chainStyle="spread">
</Constraint>
</ConstraintSet>
<ConstraintSet android:id="#+id/end">
<Constraint
android:id="#+id/testId"
android:layout_width="match_parent"
android:layout_height="0dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintTop_toTopOf="parent"
motion:layout_constraintVertical_chainStyle="spread">
</Constraint>
</ConstraintSet>
</MotionScene>
Using the following files you can regenerate the problem.Thanks for reading.Any help would be appreciated.
finally fixed this bug at androidx.constraintlayout:constraintlayout 2.0.0-beta4
I was facing a similar issue while using MotionLayout to collapse the header. The swipe performance was terrible. So I read #8KCreativeCommons comment saying that this may be caused by the change in the recyclerview size.
Setting a fixed recyclerview height instead of the 0dp(match constraint) improved the swipe performance:
private void setRecyclerViewHeight() {
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int height = displayMetrics.heightPixels;
mRecyclerView.getLayoutParams().height = height;
}
In your case, you would have to set a fixed size to your relative layout #+id/testId.
It would also be necessary to remove the layout_constraintBottom_toBottomOf="parent"

Overlap the layout in the android ExpandableListView

In the following template , at the above New vhd text,
overlap the row , I want to fix this problem .I tried to change the height of the Main File but no used.I just increase the text Size 14 to 15 PX in the all template ,size increased in main template programmatically, this problem occur. I attached my code with the question also see the commented section in XML file.Please suggest me solution if any.I am new to android .Not familiar with the android.I also attached the image below.Thank you.
//Main file
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" //Changed the height but not work
android:background="#ffffff">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="35dp"
android:orientation="vertical"
android:background="#color/green">
<TextView
android:id="#+id/queue_header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#color/white"
android:text="Inbox"
android:textStyle="bold"
android:gravity="center_vertical"
android:layout_marginLeft="10dp" />
</LinearLayout>
<ExpandableListView android:id="#+id/que_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content" //changed as fill_parent but not worked
android:groupIndicator="#drawable/settings_selector"/>
</LinearLayout>
//Second File
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"> //changed as fill_parent but not worked
<TextView android:id="#+id/groupname"
android:paddingLeft="50px"
android:paddingTop="10px"//changed as 15px not worked
android:paddingBottom="10px"//changed as 15px not worked
android:textSize="15px"
android:textColor="#0b730b"
android:layout_width="250px"
android:layout_height="wrap_content"/>//changed as fill_parent but not worked
</LinearLayout>
//Third file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">//changed as fill_parent but not worked
<ImageView
android:id="#+id/imageView1"
android:paddingLeft="40px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="#drawable/green" />
<TextView android:id="#+id/childname"
android:paddingLeft="20px"
android:paddingTop="10px"
android:paddingBottom="10px"
android:textSize="15px"
android:textColor="#0b730b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="#+id/child_id"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="#+id/dept_id"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="#+id/rgb"
android:textSize="16px"
android:layout_marginLeft="10px"
android:textColor="#0b730b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>

Android nested layout with layout_weight

I would like to create left and right reserved spaces (LinearLayout) on screen which give me felexiblitiy to ensure my UI is working in different size of screen as I want,
and in middle create a TableLayout to apply views and contorls, everything good great
except TableRow - android:layout_width is became zero, TableLayout width is not really zero however I had to put android:layout_width="0dp" for TableLayout to force android:layout_weight="4" working
how can I tell TableRow to take actual parnt(TableLayout) width
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="#+id/widget32"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:id="#+id/widget33"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1">
</LinearLayout>
<TableLayout
android:id="#+id/widget34"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="4">
<TableRow
android:id="#+id/widget64"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/widget72"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I m here" />
</TableRow>
</TableLayout>
<LinearLayout
android:id="#+id/widget35"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1">
</LinearLayout>

Resources