Have an ImageView with same width and height in ConstraintLayout - imageview

How can we make ImageView width and height equal to width of parent ConstraintLayout? So it displays a full width square ImageView.
Generally how can one set HEIGHT of some widget equal to WIDTH of other?

The following layout will place a square blue image in the center of the parent ConstraintLayout. The key piece is app:layout_constraintDimensionRatio="1:1". Refer to the documentation for details.
You can also define one dimension of a widget as a ratio of the other one. In order to do that, you need to have at least one constrained dimension be set to 0dp (i.e., MATCH_CONSTRAINT), and set the attribute layout_constraintDimensionRatio to a given ratio.
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#android:color/holo_blue_light"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

Related

Resize an stretched Vector in ImageView - Android Studio

I've been searching this for a while but didn't found nothing. How can I resize an Vector inside an ImageView?
I tried a lot of things but didn't work. The vector is shown stretched like that:
My code is:
<com.google.android.material.card.MaterialCardView
android:id="#+id/card_view"
android:layout_width="240dp"
android:layout_height="140dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="#+id/buton_add_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/ic_add_image"
android:contentDescription="#string/add_image" />
</com.google.android.material.card.MaterialCardView>

Snackbar coming below the software buttons in Marshmallow

My Snackbar coming below the software buttons in Marshmallow:
I have tried changing the view, but it is not helping.
Usually Snackbar requires the CoordinaterLayout or window decor's content which are considered as parent layout for Snackbar. Previously, it was not getting any parent layout so it directly considered WindowManager layout as parent layout. Using CoordinaterLayout as parent layout it, solved the problem.
The sample code for CoordinaterLayout is as follows:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:nimbuzz="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent">
</android.support.design.widget.CoordinatorLayout>

fitsSystemWindows effect gone for either one of two fragments with CoordinatorLayout

I have an activity (contains 4 fragments) with transparent status bar. Two of the four fragments have AppBarLayout to collapse the toolbar. In order to avoid the AppBarLayout was draw behind the transparent status bar, I have:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/first_coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:statusBarBackground="#color/blue"
>
and
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/second_coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:statusBarBackground="#color/yellow"
>
in the these two fragments. I added android:fitsSystemWindows="true" for both of the fragment.
However, only one of the two fragments work properly. One is draw BELOW the status bar while the other one is still draw BEHIND the status bar. Do you guys have any idea why only one works?
Thanks!

Android zoom and pan overlay UI according to ImageView(Touch) matrix

I'm trying to create an interface that has a map (image) with clickable elements like text or buttons as overlay. The map is an ImageViewTouch element (src: https://github.com/sephiroth74/ImageViewZoom) and has zooming and panning capabilities through touch.
My current layout is as follows:
<it.sephiroth.android.library.imagezoom.ImageViewTouch
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:clickable="true" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:shadowColor="#000"
android:text="This is some random text"
android:textSize="22sp" />
</RelativeLayout>
The question is, how can I 'lock' the position of the TextView (and other elements) to the location according to the map. So the TextView moves and resizes as the user zooms or pans the image.
I'm new to Android UI development so I don't know what direction to take, like iterating over all elements and moving/resizing them according to the image scale and scroll values or...

LinearLayout android orientation

Heading ##I have one simple question.
I'm doing UI for the app.
I'm using a linearLayout, and to apply padding for my content, I'm using second LinearLayout inside the first o
So i found an xml example, But I can't understand why it is using two difrents orientation in Linearlayout?
So in the main Linearlayout orientation is set to horizontal, but in second linearLayout (which is inside the first one) orientation is set to vertical. And for me it is nonsense, why you should use a Horizontal orientation in main Linearlayout, if all content (buttons and textview) should be displayed only verticaly.
Thank you!
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#color/background"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="30dip"
android:orientation="horizontal" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/main_title"
android:layout_gravity="center"
android:layout_marginBottom="25dip"
android:textSize="24.5sp"/>
<Button
Perhaps in linearLayout, the programmer wanted to have TextView and Button beside each other in a same line.

Resources