当前位置:   article > 正文

Android安卓开发之小项目一_android开发小项目实例

android开发小项目实例

 

 1. 创建Activity -> Empty Activity,命名testview

2. 编辑主页面,线性布局,orientation设置垂直分布,写两个按钮,id分别为btn_textview和btn_photoview

 

  1. <Button
  2. android:id="@+id/btn_textview"
  3. android:layout_width="match_parent"
  4. android:layout_height="wrap_content"
  5. android:text="2020年9月9日"
  6. />
  7. <Button
  8. android:id="@+id/btn_photoview"
  9. android:layout_width="match_parent"
  10. android:layout_height="wrap_content"
  11. android:text="沉迷于宝bei的美色"
  12. android:textColor="#FFF68F"
  13. />

测试截图:

 

3. 后端Java代码中,先构建2个按钮对象,方法中对按钮设置点击事件,点击按钮跳转到新页面。注意两个对象分别通过id查找视图。

  1. private Button BtnTextView; // 构建第一(btn_textview)个Button按钮对象
  2. private Button BtnPhotoView; // 构建第二(btn_photoview)个Button按钮对象
  1. BtnTextView = (Button)findViewById(R.id.btn_textview);
  2. BtnTextView.setOnClickListener(new View.OnClickListener(){
  3. @Override
  4. public void onClick(View view) {
  5. // 跳转到jumpAfterView
  6. Intent intent1 = new Intent(testView.this,jumpAftertestView.class);
  7. startActivity(intent1);
  8. }
  9. });
  10. BtnPhotoView = (Button)findViewById(R.id.btn_photoview);
  11. BtnPhotoView.setOnClickListener(new View.OnClickListener() {
  12. @Override
  13. public void onClick(View view) {
  14. Intent intent1 = new Intent(testView.this, jumpAfterphotoView.class);
  15. startActivity(intent1);
  16. }
  17. });

4. 创建Activity -> Empty Activity

编辑第一个跳转页面(点击第一个主页面的第一个按钮(2020年9月9日)之后的界面)

其中,①android:text可以在专门存放文本的string中定义并引用。②

  1. <TextView
  2. android:id="@+id/tv_1"
  3. android:layout_width="wrap_content"
  4. android:layout_height="wrap_content"
  5. android:text="@string/tv_test1"
  6. android:textColor="#ffc0cb"
  7. android:textSize="30sp"
  8. android:drawableTop="@drawable/jiantou"
  9. />
  10. <TextView
  11. android:id="@+id/tv_2"
  12. android:layout_width="300dp"
  13. android:maxLines="1"
  14. android:ellipsize="end"
  15. android:layout_height="wrap_content"
  16. android:text="@string/tv_test2"
  17. android:textColor="#ffc0cb"
  18. android:textSize="30sp"
  19. android:layout_marginTop="20dp"
  20. />
  21. <TextView
  22. android:id="@+id/tv_3"
  23. android:layout_width="wrap_content"
  24. android:layout_height="wrap_content"
  25. android:text="我❤好痛"
  26. android:drawableBottom="@drawable/jiantou"
  27. android:drawablePadding="-30dp"
  28. android:textColor="#00ff00"
  29. android:textSize="20sp"
  30. android:layout_margin="30dp"
  31. />
  32. <TextView
  33. android:layout_width="wrap_content"
  34. android:layout_height="wrap_content"
  35. android:text="为什么她要如此对我。我好难受,我这么在乎,我真的已经爱上她了吗,要堕入情河?"
  36. android:textColor="#EE1289"
  37. />

 

测试截图: 

 

5. 在后端代码中控制“跳转文字视图页面”,构建文本视图对象,通过id找到视图,选中对应文字内容,进行中划线以及去除锯齿操作。

private TextView testview;
  1. testview = (TextView) findViewById(R.id.tv_1); // 选中'我在学习时哭泣'
  2. testview.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG); // 中划线
  3. testview.getPaint().setAntiAlias(true); // 去除锯齿

 6. 创建Activity -> Empty Activity

编辑第二个跳转页面,点击主页面中的“沉迷于宝蓓的美色”此按钮

  1. <TextView
  2. android:layout_width="wrap_content"
  3. android:layout_height="wrap_content"
  4. android:text="❤❤❤❤❤❤爱beibei❤❤❤❤❤❤"
  5. android:drawableTop="@drawable/beibei1"
  6. />
  7. <TextView
  8. android:layout_width="wrap_content"
  9. android:layout_height="wrap_content"
  10. android:drawableTop="@drawable/beibei2"/>
  11. <Button
  12. android:id="@+id/btn_wantyou"
  13. android:layout_width="wrap_content"
  14. android:layout_height="wrap_content"
  15. android:text="亲爱的,想你"
  16. android:textColor="#00ff44"/>

7. 在java后端代码中,暂时不做对android:id="@+id/btn_wantyou"的事件点击控制。

 

 

 

 

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/251907
推荐阅读
相关标签
  

闽ICP备14008679号