景区介绍界面(Android)
来源:互联网 发布:淘宝联盟为啥登不上去 编辑:程序博客网 时间:2024/05/08 10:55
描述:自定义listview控件,通过适配器来设置数据和图片,读取txt文件来获取景点介绍信息。
activity_main.xml文件代码:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#aabbcc" android:orientation="vertical" tools:context="scenicspot.com.scenicspot.MainActivity"> <TextView android:background="#ccbbaa" android:textColor="#000000" android:padding="10dp" android:gravity="center" android:text="@string/china_spot" android:textSize="24sp" android:layout_width="match_parent" android:layout_height="wrap_content" /> <ListView android:id="@+id/scenery" android:layout_width="match_parent" android:layout_height="wrap_content" android:divider="#aaaaaa" android:dividerHeight="2dp" android:gravity="center"> </ListView></LinearLayout>item.xml文件代码:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/image" android:layout_width="100dp" android:layout_height="75dp" android:contentDescription="@string/imgText"/> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="10dp" android:orientation="vertical"> <TextView android:id="@+id/name" android:layout_width="match_parent" android:layout_height="wrap_content" android:textColor="#000000" android:textSize="20sp"/> <TextView android:id="@+id/brief" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:gravity="left" android:singleLine="true" android:ellipsize="end" android:textColor="#0000ee" android:textSize="12sp"/> </LinearLayout></LinearLayout>
scenery_show.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:background="#aabbcc" android:orientation="vertical"> <TextView android:id="@+id/title" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:padding="10dp" android:background="#ccbbaa" android:textSize="24sp"/> <ImageView android:id="@+id/image" android:layout_width="320dp" android:layout_height="240dp" android:scaleType="fitXY" android:contentDescription="@string/imgInfo"/> <TextView android:id="@+id/content" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#000000" android:textColor="#00ff00" android:textSize="16sp" android:padding="10dp"/> </LinearLayout></ScrollView>
MainActivity.java文件代码:
package scenicspot.com.scenicspot;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.widget.AdapterView;import android.widget.ListView;import android.widget.SimpleAdapter;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import java.util.Objects;public class MainActivity extends Activity { private ListView lv_scenery; private List<Map<String,Object>> list = new ArrayList<Map<String,Object>>(); private String[] names = new String[]{ "武功山","明月山","三清山","庐山","武当山","终南山","龙虎山" }; private String[] briefs = new String[]{"武功山位于中国江西省中西部,居罗霄山脉北支," + "山体呈东北——西南走向,地跨江西萍乡市芦溪县、吉安市安福县,宜春市袁州区," + "主脉绵延120余千米,总面积约970平方千米。" ,"明月山旅游区位于赣西中部有“中国宜居城市”、“国家园林城市”、“国家卫生城市”" + "、“国家绿化模范城市”、“2010中国最佳休闲养生城市”之称的宜春市中心城西南15公里处," + "旅游区面积104平方公里。","三清山又名少华山、丫山," + "位于中国江西省上饶市玉山县与德兴市交界处。" + "因玉京、玉虚、玉华三峰宛如道教玉清、上清、太清三位尊神列坐山巅而得名。其中玉京峰为最高," + "海拔1819.9米,是江西第五高峰和怀玉山脉的最高峰,也是信江的源头。三清山是道教名山," + "世界自然遗产地、世界地质公园、国家自然遗产、国家地质公园。","庐山[1] ," + "又名匡山、匡庐,是中华十大名山、世界文化遗产、" + "国家AAAAA级旅游景区、中国四大避暑胜地。地处江西省九江市庐山市境内," + "山体呈椭圆形,典型的地垒式块段山。","武当山,道教圣地," + "位于湖北省十堰市境内。武当山又名太和山、谢罗山、参上山、仙室山," + "古有“太岳”、“玄岳”、“大岳”之称。","终南山又" + "名太乙山、地肺山、中南山、周南山,简称南山,位于秦岭山脉中段,是中国重要的地理标志," + "道教的发祥圣地。","龙虎山,位于江西省鹰潭市西南20公里处。" + "东汉中叶,正一道创始人张道陵曾在此炼丹,传说“丹成而龙虎现,山因得名。" + "其中天门山最高,海拔1300米。龙虎山是中国第八处世界自然遗产[1] ,世界地质公园[2] 、" + "国家自然文化双遗产地[3] 、国家AAAAA级旅游景区[4] 、全国重点文物保护单位。" }; private int[] imgIds = new int[]{R.drawable.wugong,R.drawable.mingyue,R.drawable.sanqing, R.drawable.lushan,R.drawable.wudang,R.drawable.zhongnan,R.drawable.longhu}; private int[] contentIds = new int[]{R.raw.wudang_into,R.raw.mingyue_into,R.raw.sanqing_into, R.raw.lushan_into,R.raw.wudang_into,R.raw.zhongnan_into,R.raw.longhu_into}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); lv_scenery = (ListView) findViewById(R.id.scenery); init(); SimpleAdapter adapter = new SimpleAdapter(this, list, R.layout.item, new String[]{"img", "name", "brief"}, new int[]{R.id.image, R.id.name, R.id.brief}); lv_scenery.setAdapter(adapter); lv_scenery.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent intent = new Intent(); intent.setClass(MainActivity.this,SceneryShowActivity.class); intent.putExtra("name",(String) list.get(position).get("name")); intent.putExtra("image",(Integer) list.get(position).get("img")); intent.putExtra("content",(Integer) list.get(position).get("content")); startActivity(intent); } }); } private void init() { for (int i =0;i < imgIds.length;i++){ Map<String,Object>item = new HashMap<String, Object>(); item.put("img",imgIds[i]); item.put("name",names[i]); item.put("brief",briefs[i]); item.put("content",contentIds[i]); list.add(item); } }}
SceneryShowActivity.java文件代码:
package scenicspot.com.scenicspot;import android.app.Activity;import android.graphics.drawable.ClipDrawable;import android.os.Bundle;import android.os.Handler;import android.os.Message;import android.view.Gravity;import android.widget.ImageView;import android.widget.TextView;import java.io.IOException;import java.io.InputStream;/** * Created by Administrator on 2017/4/19 0019. */public class SceneryShowActivity extends Activity{ private ImageView imageView; private TextView content; private TextView title; private ClipDrawable clipDrawable; private Handler mHandler; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.scenery_show); imageView = (ImageView) findViewById(R.id.image); content = (TextView) findViewById(R.id.content); title = (TextView) findViewById(R.id.title); String titleStr = getIntent().getStringExtra("name"); int image = getIntent().getIntExtra("image",R.drawable.wugong); int info = getIntent().getIntExtra("content",R.drawable.wugong1); title.setText(titleStr); clipDrawable = new ClipDrawable(getResources().getDrawable(image), Gravity.CENTER, ClipDrawable.HORIZONTAL); imageView.setImageDrawable(clipDrawable); startThread(); InputStream inputStream = getResources().openRawResource(info); content.setText(getStringFromInputStream(inputStream)); mHandler = new Handler() { @Override public void handleMessage(Message msg) { clipDrawable.setLevel(clipDrawable.getLevel() + 400); } }; } public String getStringFromInputStream(InputStream inputStream) { byte[] buffer = new byte[1024]; int hasRead = 0; StringBuilder result = null; result = new StringBuilder(""); try { while ((hasRead = inputStream.read(buffer)) != -1){ result.append(new String(buffer,0,hasRead,"GBK")); } } catch (Exception e) { e.printStackTrace(); } return result.toString(); } private void startThread() { clipDrawable.setLevel(0); new Thread(){ @Override public void run() { while (clipDrawable.getLevel() < 10000){ try { Thread.sleep(300); mHandler.sendEmptyMessage(0x11); } catch (InterruptedException e) { e.printStackTrace(); } } } }.start(); }}
raw文件截图:
运行效果图:
阅读全文
0 0
- 景区介绍界面(Android)
- android 添加界面介绍
- Android Studio界面介绍
- Android studio 界面介绍
- android studio 界面介绍
- android studio界面简单介绍
- Eclipse Android 开发界面介绍
- android界面跳转,Intent介绍
- Android学习之界面篇(三)LayoutAnimationController详细介绍
- Android开发--仿景点通景区地图SurfaceView实现
- 【Android界面实现】View Animation 使用介绍
- 【Android界面实现】Drawable Animation 使用介绍
- Android界面布局的简单介绍
- Android Launcher3 隐藏介绍、帮助界面
- Android Interface(UI) 界面控件介绍
- Ribbon 界面介绍(1)
- Android学习之界面篇(一)Android Animation简单介绍
- android studio 系统学习笔记(一)android studio界面介绍
- 八种常见的排序算法
- 第十五天:对象流EOFException的异常捕获
- c:forEach 遍历集合中的元素,判断是否是最后一个元素
- Hadoop基础教程-第5章 YARN:资源调度平台(5.3 YARN集群配置)(草稿)
- 广播域与冲突域有何区别
- 景区介绍界面(Android)
- 20170523
- POJ
- 用一条for语句计算1-15中奇数的和
- MFC对话框里利用CHtmlView加载界面(四)————分层窗口设置
- hibernate对象状态
- Android studio中集成百度地图+百度定位+导航SDK冲突导致部分手机出现“百度导航引擎初始化失败”解决方案
- java的会话管理:Cookie和Session
- 遇到人才了