Issue
I'm trying to put two floating button next to each other, I tried moving it with the design view but I can't move the button it goes back to the same spot.
I'm still confused about ConstraintLayout, Relativelayout and LinearLayout terms.
From what I've read LinearLayout is for Horizontal view so I tried changing my layout width and height to wrap content
Here is my current result
activity_main
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="9dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="9dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/resultText"
android:layout_width="363dp"
android:layout_height="wrap_content"
android:autoLink="all"
android:autofillHints="text edit"
android:background="@drawable/bg_edit"
android:gravity="top"/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/saveBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/pdfBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:orientation="vertical"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
Solution
As Your button's are in LinearLayout which has Vertical
Orientation, due to that your button's are stacked upon each other if you put them in a container and then align them next to each other then it will work.
For Explanation purpose i have used Constraint Layout
the Constraint are set such as to constraint Save Button
next to pdf Button
and pdf Button
to the end of the Parent.
Try Below Code
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="9dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="9dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/resultText"
android:layout_width="363dp"
android:layout_height="wrap_content"
android:autoLink="all"
android:autofillHints="text edit"
android:background="@drawable/bg_edit"
android:gravity="top" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/saveBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/pdfBtn"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/pdfBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
Answered By - Anmol
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.