【问题标题】:Android scroll view / background image / XamarinAndroid滚动视图/背景图像/ Xamarin
【发布时间】:2015-07-29 10:49:57
【问题描述】:

我想创建背景图像大小大于屏幕的滚动视图,以执行“长滚动页面”应用程序。我正在使用以下 XML 进行布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:p1="http://schemas.android.com/apk/res/android"
    p1:minWidth="25px"
    p1:minHeight="25px"
    p1:layout_width="match_parent"
    p1:layout_height="match_parent"
    p1:id="@+id/relativeLayout1">
    <ScrollView
        p1:minWidth="25px"
        p1:minHeight="25px"
        p1:layout_width="wrap_content"
        p1:layout_height="wrap_content"
        p1:id="@+id/scrollView1"
        p1:background="@drawable/wallpaper"

        />
</RelativeLayout>

我的壁纸(背景图片尺寸为 1920x820。

问题: 如果我使用滚动视图标签,为什么我的运行应用程序的背景总是调整为屏幕大小?

我想要达到的目标: 和这里一样的效果: http://developer.xamarin.com/recipes/ios/content_controls/scroll_view/use_a_scrollview/

测试环境 Nexus 4 模拟器

【问题讨论】:

  • 尝试在你的 scrollView 中添加一个 ImageView 并将该图像视图的图像源设置为你的背景图像

标签: android xamarin scrollview


【解决方案1】:

可滚动内容是您ScrollView 中的任何内容。在这种情况下,您所要做的就是在您的ScrollView 中创建一个ImageView,并将src 属性设置为@drawable/wallpaper

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:p1="http://schemas.android.com/apk/res/android"
    p1:minWidth="25px"
    p1:minHeight="25px"
    p1:layout_width="match_parent"
    p1:layout_height="match_parent"
    p1:id="@+id/relativeLayout1">
    <ScrollView
        p1:minWidth="25px"
        p1:minHeight="25px"
        p1:layout_width="wrap_content"
        p1:layout_height="wrap_content"
        p1:id="@+id/scrollView1">

        <ImageView
            p1:layout_width="wrap_content"
            p1:layout_height="wrap_content"
            p1:src="@drawable/wallpaper"/>
        </ScrollView>
</RelativeLayout>

Ps:我也会把“p1”改成“android”,因为这是常用的命名方式,avoid using px

【讨论】:

  • 我尝试了这个解决方案,现在我可以滚动但图像仍然被压缩(图像上方和下方都有黑色条纹)所以滚动不是在图像上而是在图像+布局上。我应该为图像设置一些宽度、高度属性以避免这种情况吗?
猜你喜欢
  • 1970-01-01
  • 2016-08-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-03
  • 2013-07-15
  • 2013-03-25
  • 1970-01-01
相关资源
最近更新 更多