【问题标题】:Get screen sizes & set them in carousel view android获取屏幕尺寸并在轮播视图 android 中设置它们
【发布时间】:2013-07-22 13:54:57
【问题描述】:

在这里你可以看到我的轮播布局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...

谁能帮帮我。谢谢

【问题讨论】:

  • match_parents 用于layout_widthlayout_height 有什么问题?

标签: android carousel


【解决方案1】:
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));

【讨论】:

  • 这里我不能给出命令“display.getSize(size)”。因为在 Display 类中未定义 getsize(size) 方法。有什么办法可以解决这个问题.....
  • 是的,API级别低于13还有其他方法,试试这个 Display display = getWindowManager().getDefaultDisplay(); int 宽度 = display.getWidth(); int 高度 = display.getHeight();这些方法实际上在 API 级别 13 之后已被弃用,因此如果您想制作 API 级别 13+ 的项目,请使用之前的 getSize();
【解决方案2】:

首先你得到设备大小,即

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-06-04
    • 1970-01-01
    • 2014-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-06
    相关资源
    最近更新 更多