0

I have a design in which i need to get image view in centre alignment. how can i manage to get a image view with centered image and make its size compatible with all screens.if i give hard code size ,that doesn't set on some devices.Do i have to make design for all screens individual or i can manage it somehow through one XML. here is my XML file :

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:layout_margin="5dp"
    android:padding="5dp"> <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/backgrondcolor"
        android:orientation="horizontal"
        android:weightSum="4"> <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="2"
            android:orientation="vertical"> <ImageView
                android:id="@id/image"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:cropToPadding="true"
                android:scaleType="fitXY"
                android:src="@drawable/image_corner" />  </LinearLayout>  <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_margin="7dp"
            android:layout_weight="1.8"
            android:orientation="vertical"
            android:weightSum="5.5">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1.5">  <TextView
                    android:id="@+id/assemblyName"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:maxLines="2"
                    android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
                    android:textColor="@color/colortoolbartitle"

                    />  </LinearLayout> <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="3"> <TextView
                    android:id="@+id/asemblyinformation"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textAppearance="@style/Base.TextAppearance.AppCompat.Small"
                    android:textColor="@color/colortoolbartitle" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:orientation="horizontal"
                android:weightSum="7">

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1">

                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:src="@drawable/image" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1.5">

                    <TextView
                        android:id="@+id/totalassemblies"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:src="@mipmap/ic_launcher"
                        android:textAppearance="@style/Base.TextAppearance.AppCompat.Small"
                        android:textColor="@color/colortoolbartitle" />
                </LinearLayout>

<LinearLayout android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_weight="2">
<ImageView android:id="@+id/imageweb"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="@drawable/web" />
</LinearLayout> <LinearLayout android:layout_width="0dp"
android:layout_height="match_parent" android:layout_weight="2">
<ImageView android:id="@+id/imagenextpage"
android:layout_width="match_parent"
android:layout_height="match_parent" android:clickable="true"
android:src="@drawable/link" /> </LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout> </LinearLayout>
InsaneCat
  • 2,115
  • 5
  • 21
  • 40
  • 2
    You need to add different layouts for different screen sizes. Like layout-320dp, layout-360dp as mentioned [here](https://developer.android.com/training/multiscreen/screensizes.html). Its basically same code for all the layouts just small alignments need to be done. – Rakesh Polo Oct 23 '17 at 10:45
  • 2
    Can you quote any example please? –  Oct 23 '17 at 10:50
  • 1
    you have to make different designs. check out this lnk. may be will help you. https://stackoverflow.com/questions/8255985/how-to-support-different-screen-size-in-android – ASIF RAZA Oct 23 '17 at 11:08

0 Answers0