设置宽度和高度以填充父级 Android 幻灯片
我想制作一个幻灯片以全屏显示图像,但我得到的代码使用绝对大小,我需要将其更改为 fill_parent 但我不能。
这是代码,
public class SlideShow extends 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;
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.
here is the code,
public class SlideShow extends 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;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请注意,可能没有必要创建自定义视图,因为一个或多个现有视图可能会执行您想要的操作。特别是,您可能想看看 ImageView 和 ImageSwitcher。
您可以在 ImageSwitcher 演示应用程序中看到这些视图的实际效果。在 Android 模拟器中,启动 API 演示应用程序,选择“视图”,然后选择 ImageSwitcher。
此示例的代码位于 http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/ImageSwitcher1.html。该代码还包含在 Android SDK 安装的示例目录中。
即使您不想使用 ImageSwitcher,您可能仍然有兴趣了解该示例如何使用 LayoutParams.MATCH_PARENT。 (要支持旧版本的 Android,请将 MATCH_PARENT 替换为 FILL_PARENT。)
根据您的应用程序,仅处理 XML 中的布局可能会更简单,在 XML 中将宽度和高度设置为 match_parent (或 fill_parent)非常简单。
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.
You can see these views in action in the ImageSwitcher demo application. In an Android emulator, launch the API Demos app, select Views, and then ImageSwitcher.
The code for this example is available at 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.
Even if you don't want to use an ImageSwitcher, you may still be interested to see how the example uses LayoutParams.MATCH_PARENT. (To support older versions of Android, replace MATCH_PARENT with 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).