0
votes

Here you can see my carousel layout xml file.

 <com.touchmenotapps.carousel.simple.HorizontalCarouselLayout
        android:id="@+id/carousel_layout_event"
        android:layout_width="600dp"
        android:layout_height="500dp"
        android:layout_above="@+id/relativeLayout1"
        android:layout_alignTop="@+id/carousel_layout" >

    </com.touchmenotapps.carousel.simple.HorizontalCarouselLayout>

I want to set the running android simulator screen width & height to the android:layout_width & android:layout_height...

can anyone help me. thanks

2
What's wrong in having match_parents for layout_width and layout_height? - gunar

2 Answers

0
votes
HorizontalCarouselLayout hcl=(HorizontalCarouselLayout)findViewById(R.id.carousel_layout_event);

Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;

hcl.setLayoutParams(new LayoutParams(width,height));
0
votes

Firs you get the divice size i.e.

Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int divWidth= size.x;
int divHeight = size.y;

Create a function to set the layout params. i.e.

public void setWidthHeight(View v, int width, int height){
    LayoutParams lp;
    lp = v.getLayoutParams();
    lp.width = width;
    lp.height = height;
    v.setLayoutParams(lp);
}

then call this function as,

setWidthHeight(yourView,divWidth,divHeight);