currently I'm currently trying to achieve a squared ImageViews inside a TableRows which is supposed to be squared even if the columns are stretched but unfortunately it doesn't work the way I expected it to be. The plan is pretty simple. Use a TableLayout to host a number of ImageViews but make those imageviews squared inside even if the it is stretched. Here's what I tried so far.
<RelativeLayout 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"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MyActivity">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="*">
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:baselineAligned="false">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/img1"
android:src="#drawable/ic_launcher"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
android:cropToPadding="true"
android:layout_alignTop="#+id/img2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/img2"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/img1"
android:layout_toEndOf="#+id/img1"
android:src="#drawable/ic_launcher"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
android:cropToPadding="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/img3"
android:layout_toEndOf="#+id/img2"
android:src="#drawable/ic_launcher"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
android:cropToPadding="true"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/img2" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tableRow">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/img4"
android:src="#drawable/ic_launcher"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
android:cropToPadding="true"
android:layout_alignTop="#+id/img6"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/img5"
android:layout_toEndOf="#+id/img6"
android:src="#drawable/ic_launcher"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
android:cropToPadding="true"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/img6" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/img6"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/img4"
android:layout_toEndOf="#+id/img4"
android:src="#drawable/ic_launcher"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
android:cropToPadding="true" />
</TableRow>
</TableLayout>
</RelativeLayout>
I expect the image to fill the width and height on those imageViews to create squared images based on my original image using this code:
private Bitmap sliceImage(int my_img, int col, int row) {
/*send the original full image int id here then slice and return per icon*/
Bitmap icon = BitmapFactory.decodeResource(getResources(), my_img);
int width = icon.getWidth();
int height = icon.getHeight();
int crop_width = width / 3;
int crop_height = height / 3;
Bitmap test = Bitmap.createBitmap(icon, col * crop_width, row * crop_height, crop_width, crop_height);
return test;
}
and this to set:
ImageView img1 = (ImageView) findViewById(R.id.img1);
img1.setImageBitmap(sliceImage(R.drawable.my_img,0,0));
and so on. But the the image is just stretched on its width but the height is not adjusted.
For sample it looks like this:
Where it should be more like this but stretched in both width and height:
Related
What I have
I have ImageUri from server , & I am setting it to my NetworkImageview Volley library
What I want
I want the image to occupy full width & height of the NetworkImageview (wanted similar to facebook)
My problem
I see width of my NetworkImageview in white colour left
My code
xml layout
<RelativeLayout
android:id="#+id/relative_profile_hotot"
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_below="#+id/relative_profile_header"
android:padding="0dp">
<com.android.volley.toolbox.NetworkImageView
android:id="#+id/img_post_photo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="center"
android:src="#drawable/image_palce" />
<RelativeLayout
android:id="#+id/relative_profile_footer"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="#color/profile_footer_bg">
<TextView
android:id="#+id/tv_profile_photo_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:drawableLeft="#drawable/ic_home_place"
android:drawablePadding="5dp"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:textColor="#color/grey_dark"
android:textSize="#dimen/txt_small"
tools:text="Paris France" />
<TextView
android:id="#+id/tv_profile_photo_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/tv_profile_photo_location"
android:layout_marginLeft="20dp"
android:ems="40"
android:padding="2dp"
android:singleLine="true"
android:textColor="#color/grey_light"
android:textSize="#dimen/txt_very_small"
tools:text="Effel Tower,...Read more" />
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/img_foot"
android:src="#drawable/ic_home_footstep_color"
android:padding="5dp"
android:layout_alignParentTop="true"
android:layout_toEndOf="#+id/tv_profile_comment" />
<TextView
android:id="#+id/tv_profile_foot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="10dp"
android:paddingTop="0dp"
android:textColor="#color/grey_light"
android:textSize="#dimen/txt_small"
tools:text="150"
android:layout_alignBottom="#+id/tv_profile_photo_description"
android:layout_alignEnd="#+id/tv_profile_photo_description" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/img_cheers"
android:src="#drawable/ic_home_cheers_color"
android:padding="5dp"
android:layout_alignParentTop="true"
android:layout_toStartOf="#+id/img_comment"
android:layout_marginEnd="14dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/img_comment"
android:src="#drawable/ic_home_coments"
android:padding="5dp"
android:layout_alignParentTop="true"
android:layout_alignStart="#+id/tv_profile_comment" />
<TextView
android:id="#+id/tv_profile_comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="10dp"
android:paddingTop="0dp"
android:textColor="#color/grey_light"
android:textSize="#dimen/txt_small"
tools:text="264"
android:layout_alignBottom="#+id/tv_profile_photo_description"
android:layout_toStartOf="#+id/tv_profile_foot" />
<TextView
android:id="#+id/tv_profile_cheers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingRight="10dp"
android:paddingTop="0dp"
android:textColor="#color/grey_light"
android:textSize="#dimen/txt_small"
tools:text="3164"
android:layout_alignBottom="#+id/tv_profile_photo_description"
android:layout_toStartOf="#+id/img_comment" />
</RelativeLayout>
</RelativeLayout>
Adapter.java
myBucketListViewHolder.imgPostPic.setImageUrl(model.Uri, imageLoader);
myBucketListViewHolder.imgPostPic.setDefaultImageResId(R.drawable.im_default_cover);
screen shot :(
Replace
android:scaleType="center"
with
android:scaleType="centerCrop"
in your NetworkImageView
The same thing happened to me using NetworkImageView the problem is that it behaves a little different to ImageView and not enough with android: scaleType = "centerCrop" to fill the width when the density of the screen is greater than the width of the image you want insert.
Try this code, at runtime change the width of the image adjusting it to the density of the screen.
In your layout.xml
<com.android.volley.toolbox.NetworkImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:scaleType="fitCenter"
android:background="#android:color/transparent"
android:id="#+id/imagePagerView"/>
In your activity (i have in adapter)
Display display = ((Activity) context).getWindowManager().getDefaultDisplay();
DisplayMetrics outMetrics = new DisplayMetrics();
display.getMetrics(outMetrics);
float scWidth = outMetrics.widthPixels;
float scHeigh = outMetrics.heightPixels;
mImageView.getLayoutParams().width = (int) scWidth;
mImageView.getLayoutParams().height = (int) scHeigh;
Iam creating an app to access images from gallery or camera. For this i have an imageview with 280/280dp dimension. How to Scale images from camera/gallery(which are bigger images) to below imageview perfectly having fixed width and height without distorting the image in Android:
<ImageView
android:layout_width="280dp"
android:layout_height="280dp"
android:id="#+id/mainImage"
android:background="#drawable/profile_settings_main_image"
android:layout_marginTop="19dp"
android:layout_below="#+id/container_toolbar"
android:layout_centerHorizontal="true"
android:focusable="false"
android:adjustViewBounds="true"
/>
activity_main.xml(Full Layout)
<RelativeLayout 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="in.ABC.activity.ProfileSettings"
android:background="#93BFB6">
<LinearLayout
android:id="#+id/container_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar" />
</LinearLayout>
<TextView android:layout_width="230dp"
android:layout_height="50dp"
android:textSize="22sp"
android:background="#drawable/profile_settings_name"
android:id="#+id/nameView"
android:textColor="#000000"
android:layout_marginTop="20dp"
android:layout_below="#+id/mainImage"
android:layout_alignLeft="#+id/mainImage"
android:layout_alignStart="#+id/mainImage"
android:layout_marginRight="1dp"
android:gravity="center"/>
<ImageView
android:layout_width="280dp"
android:layout_height="280dp"
android:id="#+id/mainImage"
android:background="#drawable/profile_settings_main_image"
android:layout_marginTop="19dp"
android:layout_below="#+id/container_toolbar"
android:layout_centerHorizontal="true"
android:focusable="false"
android:adjustViewBounds="true"
/>
<ImageButton
android:layout_width="50dp"
android:layout_height="100dp"
android:id="#+id/editName"
android:background="#drawable/profile_settings_image"
android:layout_alignTop="#+id/nameView"
android:layout_toRightOf="#+id/nameView"
android:layout_toEndOf="#+id/nameView"
android:layout_alignBottom="#+id/nameView" />
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/editImage"
android:background="#drawable/profile_settings_image_2"
android:layout_alignBottom="#+id/mainImage"
android:layout_alignRight="#+id/mainImage"
android:layout_alignEnd="#+id/mainImage"
android:focusable="true" />
</RelativeLayout>
If the image's scale factor doesn't match the ImageView's scale factor, then you cannot match the height/width without sacrificing the clarity. You'll have to compromise and decide if you want to have some of the image cut off, or have the entire image fit inside but acknowledge that there will be some left over space.
See here for more information regarding android:scaleType http://www.techrepublic.com/article/clear-up-ambiguity-about-android-image-view-scale-types-with-this-guide/
You can try Android ImageView.ScaleType:
<ImageView
android:layout_width="280dp"
android:layout_height="280dp"
android:id="#+id/mainImage"
android:background="#drawable/profile_settings_main_image"
android:layout_marginTop="19dp"
android:layout_below="#+id/container_toolbar"
android:layout_centerHorizontal="true"
android:focusable="false"
android:adjustViewBounds="true"
android:scaleType="fitXY"
/>
Result of the code:
Result of the code
The original image:
Original Picture
I want to build a UI like this http://postimg.cc/image/fihidv1rv/ .
Here is my xml code for it,
for my design, I want "EFFECT" & "CAMERA" to combine as one ImageView like "SHOP" in the link
so there will be total 5 ImageViews, and I set the id as they named in the link
the problem is, how can I set the height and width with percentage?
effect+camrea: height 25%,width 100%
collage: height 25%,width 50%
draw: height 25%,width 50%
photo: height 50%,width 50%
shop: height 25%,width 100%
<RelativeLayout android:id="#+id/mainContent" android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="horizontal" android:background="#ffffff">
<ImageView
android:id="#+id/img_effect+camera"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:src="#drawable/a" />
<ImageView
android:id="#+id/img_collage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/img_effect+camera"
android:src="#drawable/b" />
<ImageView
android:id="#+id/img_draw"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/img_effect+camera"
android:layout_toRightOf="#+id/img_collage"
android:src="#drawable/c" />
<ImageView
android:id="#+id/img_photo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_toRightOf="#+id/img_collage"
android:layout_below="#+id/img_draw"
android:src="#drawable/d" />
<ImageView
android:id="#+id/img_shop"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/img_photo"
android:src="#drawable/e" />
</RelativeLayout>
You can consider using android:layout_weight param in the layout
http://developer.android.com/reference/android/widget/LinearLayout.LayoutParams.html#attr_android:layout_weight
<LinearLayout android:id="#+id/mainContent" android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="vertical" android:background="#ffffff">
<!-- height 25% -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<ImageView
android:id="#+id/img_effect"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="#drawable/a" />
<ImageView
android:id="#+id/img_camera"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="#drawable/a" />
</LinearLayout>
<!-- height 50% -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:orientation="horizontal">
<!-- width 50% -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<!-- height 50%% -->
<ImageView
android:id="#+id/img_collage"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:src="#drawable/a" />
<!-- height 50%% -->
<ImageView
android:id="#+id/img_draw"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:src="#drawable/a" />
</LinearLayout>
<!-- width 50% -->
<ImageView
android:id="#+id/img_photo"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:src="#drawable/b" />
</LinearLayout>
<!-- height 25%% -->
<ImageView
android:id="#+id/img_shop"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:src="#drawable/e" />
Its hard to it in Xml, you can do it by code doing some calculations.
How to do:
Get mainContent height & width, which is your parent view.
GetLayoutparams of each imageVIew, and set height & width,by calculating percentage height & width
Sample Code:
(in activity)
final View parentView= findViewById(R.id.mainContent);
final ImageView effect_camera= (ImageView)findViewById(R.id.img_effect+camera);
effect_camera.post(new Runnable(){
#Override
public void run(){
int height=parentView.getHeight();
int width=parentView.getWidth();
RelativeLayout.LayoutParams lp= (RelativeLayout.LayoutParams)effect_camera.getLayoutParams();
int percentHeight=height*.25;
int percentWidth= width*1;
lp.height=percentHeight;
lp.width=percentWidth;
effect_camera.setLayoutParams(lp);
}
});
I have an Android horizontal LinearLayout with 5 images in it. I want the 5 images to fit the screen horizontally while keeping the aspect ratio. Each image is 128x128 pixel.
The problem is that while the width is set like what I wanted the height of the images remain the same, so they look like this on a bigger screen (this is the Nexus 7):
What I have now:
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:cropToPadding="true"
android:scaleType="fitXY"
android:src="#drawable/image01" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scaleType="fitXY"
android:src="#drawable/image02" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scaleType="fitXY"
android:src="#drawable/image03" />
<ImageView
android:id="#+id/imageView4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scaleType="fitXY"
android:src="#drawable/image04" />
<ImageView
android:id="#+id/imageView5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scaleType="fitXY"
android:src="#drawable/image05" />
</LinearLayout>
Thanks for the help
change the scaleType to centerInside or fitCenter and height to match parent.
try to surround the imageview with a horizontal LinearLayout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_weight="1"
android:layout_gravity="center">
<ImageView
android:id="#+id/btnHome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tag="btnhome" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_weight="1"
android:layout_gravity="center">
<ImageView
android:id="#+id/btnGames"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tag="btngames" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_weight="1"
android:layout_gravity="center">
<ImageView
android:id="#+id/btnNews"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tag="btnnews"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_weight="1"
android:layout_gravity="center">
<ImageView
android:id="#+id/btnPayment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tag="btnpayment"/>
</LinearLayout>
then, change the scaleType to fitCenter.
it will cause your pictures to have a correct ratio event you view it in a wider screen.
I found some code to create a square view that I could then use to render my own custom graphics in. You should be able to something like this:
public class SquareImageView extends ImageView {
#Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int width = getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec);
int height = getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec);
int length = Math.min(width, height);
setMeasuredDimension(length, length);
}
}
I haven't tried this squaring code in a LinearLayout but when use RelativeLayout where it was positioned first and attached to three sizes of the parent it worked nicely. This is hoping that ImageView does the right thing with the image, otherwise you're going to have to override the onDraw() method too.
Hi i have an app that is a gallery of images.
The problem is that, i have buttons to move between images on the center of the app and i want them at 75% of the margin of top.
The question is : Can i put it on % of the screen instead of dp?
The error is that if i use margin_bottom it crashes.
Here is my code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/color_fondo"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<ImageView
android:id="#+id/barra"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:scaleType="fitXY"a
android:src="#drawable/cabecera" />
<ImageView
android:id="#+id/img1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/barra"
android:paddingTop="#dimen/activity_vertical_margin"
android:scaleType="fitXY"
android:src="#drawable/ic_launcher" />
<ProgressBar
android:id="#+id/pb1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/img1"
android:layout_centerHorizontal="true"
android:visibility="invisible" />
<ImageButton
android:id="#+id/imgbtnshare1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#null"
android:paddingBottom="5dp"
android:src="#drawable/compartir4" />
<ImageButton
android:id="#+id/imgbtn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/imgbtnshare1"
android:layout_alignParentLeft="true"
android:layout_marginBottom="100dp"
android:background="#null"
android:src="#drawable/izquierda42" />
<ImageButton
android:id="#+id/imgbtn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/imgbtn2"
android:background="#null"
android:src="#drawable/derecha42" />
</RelativeLayout>
You may get the Layout size and then calculate your buttons top margin as proportion of that:
NOTE: You cannot get the layout size in onCreate() since it's not set yet. Do it in onWindowFocusChanged method of your Activity.
RelativeLayout relativeLayout = (RelativeLayout)findViewById(R.id.YourXML);
#Override
public void onWindowFocusChanged (boolean hasFocus) {
// The layout has been drawn here
// so the Height and Width have been computed
int width = relativeLayout.getWidth();
int height = relativeLayout.getHeight();
}
int topMargin = height * 0.75;
And set it programmatically:
LayoutParams layoutParams = new LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT
);
layoutParams.setMargins(left, top, right, bottom);
yourbutton.setLayoutParams(layoutParams);