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
Hey fellow programmers,
I was just programming in a listView and implementing actions for tapping a list element until I got to a point where I wanted to keep things recursively.
Taken this ClickListener, I would like to have the image next to the list element changed when tapped.
list.add(Model("firstelement","description 1", R.drawable.button_activated))
list.add(Model("secondelement","description 2",R.drawable.button_activated))
listview.adapter = MyAdapter(this, R.layout.row, list)
var elementArray: IntArray = intArrayOf(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
listview.setOnItemClickListener{ parent: AdapterView<*>, view: View, position:Int, id: Long ->
val currentimage = ? //here I'd like to retrieve the imageview of the tapped list item
val img: ImageView = findViewById(R.id.currentimage)
if (elementArray.get(position)==0){
img.setImageResource(R.drawable.button_activated)
elementArray.set(position,1)
}
else if (elementArray.get(position)==1){
img.setImageResource(R.drawable.button_dectivated)
elementArray.set(position,0)
The images are added to the list together with the text view.
How can I retrieve them to change them? Tried listview.getItemIdAtPosition but that leads to errors.
I bet there is a way - I just don't see it. Thanks in advance for any hint!
In addition, here is my layout row.xml where the list gets loaded into:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
>
<ImageView
android:layout_width="75dp"
android:layout_height="75dp"
android:id="#+id/image0"
android:src="#mipmap/ic_launcher"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView1"
android:text="first element"
android:textStyle="bold"
android:textSize="20sp"
android:layout_margin="5dp"
android:textColor="#000"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView2"
android:text="second element"
android:textSize="18sp"
android:layout_margin="5dp"
android:textColor="#a9a9a9"
/>
</LinearLayout>
</LinearLayout>
Just resolved it on my own with the help of this solution: Android: Dynamically change Image in Listview
Had to access the lower imageView of the current view: ImageView = view.findViewById(R.id.image)
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"
I have a popup to show in my xml. It should have a border. Following is the code:-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rl_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="20dp" >
<RelativeLayout
android:id="#+id/rl_startpopup"
android:layout_width="340dp"
android:layout_height="320dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#drawable/popup_outline"
android:orientation="vertical" />
</RelativeLayout>
The popup_outline is a shape
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:angle="270"
android:endColor="#192423"
android:startColor="#4a7669"
android:type="linear" />
<corners android:radius="8dp" />
<stroke
android:width="2dp"
android:color="#e4f4d3" />
</shape>
here is the image of the popup:-
This "popup_outline" is the white border shown. I want to use a repeatable pattern image instead of one color as the border. I have to do this in xml. Please help
You can use a FrameLayout to show the border and inside FrameLayout use ImageView or RelativeLayout to show other content.
Example:-
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/IMAGE_OF_YOUR_CHOICE_WITH_repeatable pattern"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
></RelativeLayout>
</FrameLayout>
You can use any layout to use border and inside the layout you free to use any view or layout e.g TextView, ImageView
Example:-
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/popupbox"
android:padding="50dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Your Garage is empty" />
</RelativeLayout>
when I launch my app on tablet emulator it shows different colors. See this image (I have cut the right side of the image so it shows just a part of it)
And this is from the standart smartphone emulator:
So you see that there is a strange difference. However the code is the same. Here is my layout xml:
<?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/com.markupartist.android.actionbar.example"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.markupartist.android.widget.ActionBar
android:id="#+id/actionbar"
style="#style/ActionBar"
app:title="#string/some_title" />
<RelativeLayout
xmlns:a="http://schemas.android.com/apk/res/android"
a:layout_width="fill_parent"
a:layout_height="fill_parent"
a:background="#ffffff" >
<LinearLayout
a:layout_width="fill_parent"
a:layout_height="wrap_content"
a:orientation="horizontal"
a:paddingBottom="5dip"
a:paddingLeft="5dip"
a:paddingRight="5dip"
a:paddingTop="5dip" >
<MultiAutoCompleteTextView
a:id="#+id/recipientBody"
a:layout_width="0dip"
a:layout_height="wrap_content"
a:layout_weight="1.0"
a:hint="#string/sms_to_whom"
a:maxLines="10"
a:nextFocusRight="#+id/smsRecipientButton" />
<LinearLayout
a:layout_width="wrap_content"
a:layout_height="fill_parent"
a:orientation="vertical" >
<Button
a:id="#+id/smsRecipientButton"
a:layout_width="wrap_content"
a:layout_height="0dip"
a:layout_marginLeft="5dip"
a:layout_weight="1.0"
a:enabled="true"
a:nextFocusLeft="#+id/recipientBody"
a:onClick="onPickContact"
a:text="#string/sms_contacts" />
</LinearLayout>
</LinearLayout>
<LinearLayout
a:layout_width="wrap_content"
a:layout_height="fill_parent"
a:layout_marginRight="10dip"
a:layout_marginBottom="10dip"
a:gravity="bottom"
a:orientation="vertical"
a:layout_above="#+id/bottomLayer" a:layout_alignParentRight="true">
<TextView
android:id="#+id/chars"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="" />
</LinearLayout>
<LinearLayout
a:id="#+id/bottomLayer"
a:layout_width="fill_parent"
a:layout_height="wrap_content"
a:layout_alignParentBottom="true"
a:background="#9c9e9c"
a:orientation="horizontal"
a:paddingBottom="5dip"
a:paddingLeft="5dip"
a:paddingRight="5dip"
a:paddingTop="5dip" >
<EditText
a:id="#+id/smsBody"
a:layout_width="0dip"
a:layout_height="wrap_content"
a:layout_weight="1.0"
a:autoText="true"
a:capitalize="sentences"
a:hint="#string/sms_enter_message"
a:inputType="textShortMessage|textAutoCorrect|textCapSentences|textMultiLine"
a:nextFocusRight="#+id/send_button"
a:minLines="5"
a:gravity="left|top"/>
<LinearLayout
a:layout_width="wrap_content"
a:layout_height="fill_parent"
a:orientation="vertical" >
<Button
a:id="#+id/smsSendButton"
a:layout_width="wrap_content"
a:layout_height="0dip"
a:layout_marginLeft="5dip"
a:layout_weight="1.0"
a:enabled="false"
a:nextFocusLeft="#+id/smsBody"
a:text="#string/sms_send_abbr" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
Any ideas what might be wrong or how to fix it?
It is not wrong but intended. Android uses the default style of the device / android version. The default style for tablets is different to those on smartphones. Since it is a good idea to stick to the default styles with your app this behaviour you see there is just right.