简体   繁体   English

设置宽度和高度以填充父Android幻灯片

[英]Set a Width and Height to Fill Parent Android SlideShow

i want to make a SlideShow to show the image in full screen but the code i got was using a absolute size, i need to change it to fill_parent but i can't. 我想制作一张SlideShow以全屏显示图像,但是我得到的代码使用的是绝对大小,我需要将其更改为fill_parent,但我不能。

here is the code, 这是代码,

public class SlideShow extends View { 公共类SlideShow扩展了View {

    public final int SLIDESHOW_DEFAULT_WIDTH = 300 ;
    public final int SLIDESHOW_DEFAULT_HEIGHT = 350;
    public static final int DEFAULT_CURRENT_SLIDE_INDEX_START = 0;

Note that it might not be necessary to make a custom View, as one or more of the existing Views may do what you want. 请注意,由于一个或多个现有视图可能会执行您想要的操作,因此可能不必创建自定义视图。 In particular, you might want to take a look at ImageView and ImageSwitcher. 特别是,您可能想看一下ImageView和ImageSwitcher。

You can see these views in action in the ImageSwitcher demo application. 您可以在ImageSwitcher演示应用程序中看到这些视图。 In an Android emulator, launch the API Demos app, select Views, and then ImageSwitcher . 在Android模拟器中,启动API Demos应用程序,选择Views,然后选择ImageSwitcher

The code for this example is available at http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/ImageSwitcher1.html . 该示例的代码可从http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/ImageSwitcher1.html获得 The code is also included in Android SDK installations in the samples directory. 该代码也包含在示例目录中的Android SDK安装中。

Even if you don't want to use an ImageSwitcher, you may still be interested to see how the example uses LayoutParams.MATCH_PARENT. 即使您不想使用ImageSwitcher,您仍然可能对查看示例如何使用LayoutParams.MATCH_PARENT感兴趣。 (To support older versions of Android, replace MATCH_PARENT with FILL_PARENT.) (要支持较旧的Android版本,请将MATCH_PARENT替换为FILL_PARENT。)

Depending on your app, it might be even simpler to just handle the layout in XML, where it's trivial to set widths and heights to match_parent (or fill_parent). 根据您的应用程序,以XML处理布局可能更为简单,在XML中将宽度和高度设置为match_parent(或fill_parent)很简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM