1,Gallery滑动的时候,当前的Item图片会变暗,表面浮一层白膜,紧跟的一个Item的图片会由一层白膜变成正常状态,这时只需要设置Gallery的一个属性即可。。
setUnselectedAlpha(100);设置未选中的Item的透明度为100.。。。。
2,Activity使用Dialog样式导致点击空白处自动关闭的问题
将Activity设置成窗口的样式实现Dialog或者Popupwindow效果在开发中是很常用的一种方式,在AndroidMenifest.xml中将需要设置的Activity增加android:theme="@android:style/Theme.Dialog"属性即可。但是窗口化的Activity有个问题就是:点击窗口空白处Activity会finish。如何避免这个问题呢,办法如下:
- <resources>
- <style name="Theme.SoundRecorder" parent="@android:style/Theme.Holo.DialogWhenLarge">
- <item name="android:windowCloseOnTouchOutside">false</item>
- </style>
- </resources>
- YourActivity.this.setFinishOnTouchOutside(false);
- @Override
- public boolean onTouchEvent(MotionEvent event) {
- if (event.getAction() == MotionEvent.ACTION_DOWN && isOutOfBounds(this, event)) {
- return true;
- }
- return super.onTouchEvent(event);
- }
- private boolean isOutOfBounds(Activity context, MotionEvent event) {
- final int x = (int) event.getX();
- final int y = (int) event.getY();
- final int slop = ViewConfiguration.get(context).getScaledWindowTouchSlop();
- final View decorView = context.getWindow().getDecorView();
- return (x < -slop) || (y < -slop)|| (x > (decorView.getWidth() + slop))|| (y > (decorView.getHeight() + slop));
- }
3,报异常java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread. [in ListView(2131296397, class android.widget.ListView) with Adapter(class com.etaoshi.etaoke.adapter.DishAdapter)]。。
刚开始以为是view不应该在子线程中做操作,后来修改了依然出问题。。。
最后发现,原来是adapter也不能在子线程中做setEnable(false)操作。。。郁闷了一下午。。。终于搞定了
4.在做初始化同意条款的时候,用SharePreference来保存状态值,但是从下载process进去时候,取得的状态值还是没改变的值。后来经过查找,才知道是SharePreference跨进程的问题,需要在生成SharePreference时候需要把Sharedpreferences的访问模式改为MODE_MULTI_PROCESS,这样便可以实时读取Sharedpreferences中修改后的值。另外,把AndroidMainfest.xml中的android:process=":remote"这一行去掉,把Sharedpreferences的访问模式改为MODE_PRIVATE,这样也可以实时读取。
5.用ScrollView和GridView,listview来画整个布局UI
通常ScrollView里面是不能放GridView或者ListView的,但是如果我们需要有这个需求的话,就需要对GridView或者ListView做一点儿修改,方法如下:
①自定义MyGridView,它继承自GridView或者ListView
②重写GirdView或者ListView的OnMesure方法,
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
这样,当ScrollView和GridView或者Listview一起的时候,就不会出现加载列表数据,然后GridView或者listview中的每个Item的View显示不出来的问题了。。。