Linearlayout changes size (ratio) when i set Image to ImageView

Wednesday, November 4, 2015

I have a dialog with the XML code below, what i wanted to do is just like what is showed in first screenshot (and it is exactly what is showed on the screen when i keep the imageview empty) :



Normal app running without image inside imageView



but when i put the picture inside the imageView using the code :



ImageView img1 = (ImageView) myView.findViewById(R.id.imgView1);
img1.setImageResource(R.drawable.attention);
img1.setScaleType(ImageView.ScaleType.CENTER_INSIDE);


the screen becomes :



When app runs and image inside the imageView



I dont want the linearlayout that contains the imageViews to change the ration, i put the weight ("3") to always keep same ratio, but although it changes.



above my XML source :



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="10dp"
android:orientation="vertical"
android:weightSum ="10">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:gravity="center"
android:orientation="vertical"
android:layout_weight="1"
android:background="@drawable/dialog_bg">

<TextView
android:id="@+id/txt_field1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:gravity="center"
android:orientation="vertical"
android:layout_weight="1"
android:background="@drawable/dialog_bg">

<TextView
android:id="@+id/txt_field2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="10dp"
android:paddingLeft="10dp"
android:textColor="@color/black"/>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:gravity="left"
android:orientation="vertical"
android:layout_weight="2"
android:background="@drawable/dialog_bg">

<TextView
android:id="@+id/txt_field3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="10dp"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:paddingEnd="10dp"
android:textColor="@color/black" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:gravity="left"
android:orientation="horizontal"
android:layout_weight="3"
android:background="@drawable/dialog_bg">

<ImageView
android:id="@+id/imgView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingRight="10dp"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:paddingEnd="10dp"
android:layout_weight="1"
android:scaleType = "fitXY" />

<ImageView
android:id="@+id/imgView2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingRight="10dp"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:paddingEnd="10dp"
android:layout_weight="1"
android:scaleType = "fitXY"/>

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:gravity="left"
android:orientation="horizontal"
android:layout_weight="3"
android:background="@drawable/dialog_bg">

<ImageView
android:id="@id/imgView3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingRight="10dp"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:paddingEnd="10dp"
android:layout_weight="1"
android:scaleType = "fitXY"/>

<ImageView
android:id="@id/imgView4"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingRight="10dp"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:paddingEnd="10dp"
android:layout_weight="1"
android:scaleType = "fitXY"/>

</LinearLayout>

</LinearLayout>
</RelativeLayout>


Please any suggestion how to bypass this issue. Thank you.

0 comments:

Post a Comment