`
ipjmc
  • 浏览: 702767 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Android Tricks

阅读更多

下面是总结了开发中遇到的一些小问题,解决方法很简单,持续更新
1、TextView
将Html文档显示在TextView中
textView.setAutoLinkMask(Linkify.ALL);
textView.setText(Html.fromHtml("<a href='http://ipjmc.iteye.com'>http://ipjmc.iteye.com</a>
..."));

2.EditText
指定输入特定字符
android:digits="abcdefghijklmnopqrstuvwxyz0123456789"
只能输入数字
android:inputType="number"

3.让自定义View捕获到onTouch事件
setClickable(true);
onFling事件:
setOnLongClickable(true);

4.不要调用SurfaceView的setBackground方法,否则只能看到Background,看不到Canvas上画的东东,貌似被background盖住了。

5.竖直滚动与水平滚动
ScrollView 对应 HorizontalScrollView
ListView 对应 Gallery,但是Gallery的默认属性是水平居中,要左对齐比较麻烦,很蛋疼

6.对ListView用图片作为背景会降低滚动性能,最好用纯色作为背景

7.如果使用了mWakeLock.acquire(10*1000),在10s内就不能手动调用mWakeLock.release()了,否则程序会崩溃

8.注意不能使RelativeLayout控件循环依赖,比如RelativieLayout高度为Wrap_content,子控件设置了ALIGN_PARENT_BOTTOM = true。否则,RelativeLayout高度相当于fill_parent

9.慎用Activity的singleInstance属性,性能要比singleTask差很多。

10.自定义控件继承LinearLayout,FrameLayout等时,记得设置一个background,否则onDraw()是不会执行的。

11.如果使用了compatibility package 再使用ProGuard导出Project时,会出现错误conversion to dalvik format failed with error 1,解决办法:在proguard.cfg中添加一行 -keep class android.support.v4.** { *; }

12.默认情况下在Framelayout里面子元素中使用marginTop,marginLeft没有效果,添加android:layout_gravity="top"就行了

13.解决手机模拟器无法上网问题:首先通过 adb shell进入手机模拟器的SHELL,然后用命令setprop net.dns1 8.8.8.8设置DNS

14. 如果ScrollView内部有EditView,WebView等可以Forcus的控件,ScrollView会自动滚动到该位置,禁用该特性的方法:
    mScrollView.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
    mScrollView.setFocusable(true);
    mScrollView.setFocusableInTouchMode(true);
    mScrollView.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            v.requestFocusFromTouch();
            return false;
        }
    });
分享到:
评论

相关推荐

    Android-android-tips-tricks.zip

    Android-android-tips-tricks.zip,[备忘]android开发的技巧,安卓系统是谷歌在2008年设计和制造的。操作系统主要写在爪哇,C和C 的核心组件。它是在linux内核之上构建的,具有安全性优势。

    精通Android 4 游戏开发(Advanced.Android.4.Games)

    Since their release, Android has progressed with the debut of Android 4.0, adding better fonts, new User Interface and Experience (UI/UX) APIs, tablet considerations, multi-touch capabilities, multi-...

    Android代码-震惊!如此多的Android开发技巧!!!

    一些很不错的Android开发技巧,这个项目翻译自 android-tips-tricks 去掉了一些我认为不重要的,对我使用过的东东做了评价,同时翻译了一些自己没有注意到的知识点的文章。 :heart: star 支持一下 欢迎协作 了解你的...

    Gradle for Android

    Finally, you will be shown a number of tips and tricks on the advanced customization of your application's build process. By the end of this book, you will be able to customize the entire build ...

    Android 4 游戏开发入门(Beginning Android 4 Games Development)

    Nom Invades Android * OpenGL ES: A Gentle Introduction *2D Game Programming Tricks * Super Jumper: A 2D OpenGL ES Game * OpenGL ES: Going 3D *3D Programming Tricks * Droid Invaders: the Grand Finale ...

    Introduction.to.Android.Application.Development(4th,2013.12) pdf

    I: An Overview of the Android Platform 1 Introducing Android 11 A Brief History of Mobile Software Development 11 Way Back When 11 “The Brick” 13 Wireless Application Protocol (WAP) 15 Proprietary ...

    CommonsWare.The.Busy.Coders.Guide.to.Android.Development.Version.8.2.2017

    Android, the next-generation open mobile platform from Google and the Open Handset Alliance, is poised to become a significant player in the mobile device market. The Android platform gives developers...

    Scrolling Tricks.zip

    Scrolling Tricks介绍: 实现滑动视图(ScrollView)中的头部两种滑动效果。一种是向上滑动View时,头部也向上滑动并且消失,当向下滑动时,头部马上出现,所以叫做Quick Return(如效果图1);一种是无论向上或者...

    android-tips-tricks:[备忘单] Android开发的提示和技巧

    有关Android开发的提示和技巧的备忘单。 这是我从各种来源收集到的一组有关Android开发的简单提示和技巧。 它可以帮助我指导社区中的其他android开发人员有关每个android开发人员应了解的知识。 我也可以随时随地...

    Introduction to Android™ Application Fourth Edition pdf

    Introduction to Android Application Development, Fourth Edition ...tools—the emulator and DDMS—an appendix of Android IDE tips and tricks, as well as answers to the end-of-chapter quiz questions.

    Mastering.OpenCV.Android.Application.Programming.1783988207

    The book ends with a short chapter covering useful Android tips and tricks and some common errors and solutions that people might face while building an application. By the end of the book, readers ...

    The Busy Coders Guide to Android Development最终版2019

    Key Android Concepts Choosing Your Development Toolchain Tutorial #1 - Installing the Tools Android and Projects Tutorial #2 - Creating a Stub Project Getting Around Android Studio Contents of Android...

    Android NDK Game Development Cookbook 无水印pdf 0分

    For C++ developers, this is the book that can swiftly propel you into the potentially profitable world of Android games. The 70+ step-by-step recipes using Android NDK will give you the wide-ranging ...

    Apress.Advanced.Android.4.Games.Jan.2012

    Since their release, Android has progressed with the debut of Android 4.0, adding better fonts, new User Interface and Experience (UI/UX) APIs, tablet considerations, multi-touch capabilities, multi-...

    The.Android.Game.Developers.Handbook.1785885863

    Practical tips and tricks to develop powerful Android games Learn to successfully implement microtransactions and monitor the performance of your game once it's out live. Integrate Google's DIY VR ...

    Android-kittenTricks.zip

    Android-kittenTricks.zip,React Native Starter Kit拥有40多个屏幕和现代明暗主题,可创建令人惊叹的跨平台移动应用程序。,安卓系统是谷歌在2008年设计和制造的。操作系统主要写在爪哇,C和C 的核心组件。它是在...

    Gradle.for.Android.1783986824

    Finally, you will be shown a number of tips and tricks on the advanced customization of your application's build process. By the end of this book, you will be able to customize the entire build ...

    ScrollTricks介绍

    ScrollTricks是一个开源控件,实现了两个简单功能: 1、Quick Return:向上滑动时,View也向上滑动并且消失,当向下滑动时,View马上出现。例如Google Now的搜索功能。 2、Sticky:类似的同步滚动,特定的View最多...

Global site tag (gtag.js) - Google Analytics