您的位置:首页 > 其它

单页图片和文字一起滑动的效果

2015-06-30 01:56 330 查看
由于项目中需要展示各个展馆的文字介绍以及上方配的图片,所以写此文章,记录一下,以方便以后的使用。

刚开始由于不知道最外层应该是ScrollView,所以在LinearLayout中套了一个ScrollView,导致ScrollView can host only one direct child 错误。所以在搜索了如何实现滑动图片的资源以后,首先发现最外层最好直接是ScrollView,其次可以在ImageView和TextView外层套一个LInearLayout,这个问题就解决了。

下面是XML文件。

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="200dip"
android:scaleType="fitXY"
android:src="@drawable/six"/>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/hello_world"/>
</LinearLayout>

</LinearLayout>

</ScrollView>


其次呢,ImageVIew经常会报Missing contentDescription attribute on image这个警告,主要是由于ADT会提示你定义一个android:contentDescription属性,用来描述这个控件的作用。也就是对这个控件作用的描述,随便加上一句即可,例如:android:contentDescription="@string/app_name"。

从写此页面的经历,我体会到了人不能被惯性思维所约束,不能平时习惯怎样,就认为所有的事情也应该是这样的。程序员就应该有创新意识,打破惯性思维,敢想敢试,这样才会有更大的进步。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: