A
A
artto82018-07-05 20:17:24
Android
artto8, 2018-07-05 20:17:24

How to set the location of the view in the layout?

Hey! I load different photos in an ImageView, it looks something like this

screen 1
5b3e505dcde5e788379195.jpeg

Photos of different sizes, I want the width of the ImageView to be maximum, and the height is propped up under the photo. But after changing several images I get this result
screen 2
5b3e50ee0052f702518511.jpeg

How to implement the idea? And how to set the maximum size so that the view does not go beyond the screen?
The code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".View.RepostView"
    android:orientation="vertical"
    android:padding="10dp">

    <ImageView
        android:id="@+id/iv_content"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/iv_background"
        android:contentDescription="@string/iv_description"
        android:padding="5dp"
        android:scaleType="fitCenter"
        android:layout_marginBottom="5dp"/>

    <EditText
        android:id="@+id/et_description"
        android:layout_width="match_parent"
        android:layout_height="130dp"
        android:background="@drawable/et_background"
        android:elevation="4dp"
        android:inputType="textMultiLine|textNoSuggestions"
        android:padding="5dp"
        android:textColor="@android:color/white"
        android:textSize="14sp"
        android:gravity="top"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:gravity="center_horizontal">

        <Button
            android:id="@+id/button"
            style="@style/Widget.AppCompat.Button.Colored"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:elevation="4dp"
            android:onClick="onClickSave"
            android:text="@string/b_save" />

        <Button
            android:id="@+id/button2"
            style="@style/Widget.AppCompat.Button.Colored"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:elevation="4dp"
            android:onClick="onClickRepost"
            android:text="@string/b_repost" />
    </LinearLayout>
</LinearLayout>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question