ScrollView是一个顶层布局,可以实现大于手机屏幕的布局,从而实现页面上下滑动
看代码就会理解
.xml文件
<?xml version="1.0" encoding="utf-8"?> <ScrollView android:layout_height="match_parent" android:layout_width="match_parent" xmlns:android="http://schemas.android.com/apk/res/android" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="100px" android:orientation="horizontal"> <ImageView android:layout_width="80px" android:layout_height="match_parent" android:id="@+id/headimg2"/> <TextView android:layout_width="300px" android:layout_height="match_parent" android:id="@+id/username2" android:layout_gravity="center_vertical" android:layout_marginLeft="10dp"/> </LinearLayout> <View android:layout_width="fill_parent" android:layout_height="1px" android:background="?android:attr/listDivider" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/comment2" android:layout_marginLeft="10dp"/> <ImageView android:layout_width="match_parent" android:layout_height="300dp" android:id="@+id/food1" android:padding="10dp" android:scaleType="fitXY"/> <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/food2" android:padding="10dp" android:scaleType="fitXY"/> <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/food3" android:padding="10dp" android:scaleType="fitXY"/> <View android:layout_width="fill_parent" android:layout_height="1px" android:background="?android:attr/listDivider" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/feed" android:padding="10dp"/> </LinearLayout> </ScrollView>
.java文件
package com.example.administrator.test2application; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.widget.ImageView; import android.widget.TextView; public class jumpnew2Activity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_jumpnew2); ImageView headpic= findViewById(R.id.headimg2); TextView username = findViewById(R.id.username2); TextView commentwords= findViewById(R.id.comment2); ImageView foodpic1=findViewById(R.id.food1); ImageView foodpic2=findViewById(R.id.food2); ImageView foodpic3=findViewById(R.id.food3); TextView feed=findViewById(R.id.feed); Intent intent=getIntent(); Bundle bundle=intent.getExtras(); int headimg=bundle.getInt("headpic"); headpic.setImageResource(headimg); String username1=bundle.getString("username"); username.setText(username1); String commentwords1=bundle.getString("commentwords"); commentwords.setText(commentwords1); int foodimg1=bundle.getInt("foodpic1"); foodpic1.setImageResource(foodimg1); int foodimg2=bundle.getInt("foodpic2"); foodpic2.setImageResource(foodimg2); int foodimg3=bundle.getInt("foodpic3"); foodpic3.setImageResource(foodimg3); feed.setText(" 还没人?赶紧抢沙发! " +"\n"+ " 据说第一个评论的人都有枚幸运草"); } }
上述.java代码中的intent和bundle是用于数据接收的,读者可以用其他方法或者直接写死也行,重点在布局这块。
下面是效果截图,由于没有动图,所以就截图截了两张,读者将就着看。
上述截图是本人在仿做美食天下app中该界面用的ScrollView做出来的效果,如果读者有兴趣,可以去我的github上下载源码,下面是链接:https://github.com/jiang-congcong/imitated-writing-the-Gurmet-world-of-the-topic-of-coversation