0

在这里您可以看到我的轮播布局 xml 文件。

 <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>

我想将正在运行的 android 模拟器屏幕宽度和高度设置为 android:layout_width & android:layout_height...

谁能帮我。谢谢

4

2 回答 2

0
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));
于 2013-07-22T14:04:27.270 回答
0

首先你得到设备大小,即

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

创建一个函数来设置布局参数。IE

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

然后将此函数称为,

setWidthHeight(yourView,divWidth,divHeight);
于 2013-07-22T14:10:22.300 回答