21.工作中积累的问题

2017-05-17  本文已影响13人  Jsonzhang

1. 用Android Studio怎样获取应用的签名(SHA1)?

在集成百度或是高德地图时,都需要应用的签名即SHA1证书,在Eclipse中很容易找到这个值,但是在Android Studio中却需要我们自己动手获取。

Android Studio中的Terminal里面输入:
"D:\software\path\JDK\jre\bin\keytool.exe" -list -v -keystore "C:\Users\hexun.android\debug.keystore"
路径是我电脑的路径,对应的改成你自己的路径

Paste_Image.png

输入正确后,会提示输入密匙库口令,默认是android,密码输入时不显示,但要正确输入,如果是自己更改过密码就输入自己的密码,输入后展示下面数据:

Paste_Image.png

2.ScrollView中嵌套ListView时,ListView显示不全,以及滑动冲突的解决?

public void setListViewHeightBasedOnChildren(ListView listView) {
        ListAdapter listAdapter = listView.getAdapter();
        if (listAdapter == null) {
            return;
        }

        int totalHeight = 0;
        for (int i = 0; i < listAdapter.getCount(); i++) {
            View listItem = listAdapter.getView(i, null, listView);
            listItem.measure(0, 0);
            totalHeight += listItem.getMeasuredHeight();
        }

        ViewGroup.LayoutParams params = listView.getLayoutParams();
        params.height = totalHeight
                + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
        listView.setLayoutParams(params);
    }

注意:

public class ListScrollView extends ScrollView {

    private ListView listView;

    public void setListView(ListView listView){
        this.listView = listView;
    }

    public ListView getListView(){
        return listView;
    }

    public ListScrollView(Context context) {
        this(context,null);
    }

    public ListScrollView(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public ListScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        if (listView!=null && checkArea(listView,ev)){
            return false;
        }
        return super.onInterceptTouchEvent(ev);
    }

    private boolean checkArea(View v, MotionEvent event){
        float x = event.getRawX();
        float y = event.getRawY();
        int[] locate = new int[2];
        v.getLocationOnScreen(locate);
        int l = locate[0];
        int r = l + v.getWidth();
        int t = locate[1];
        int b = t + v.getHeight();
        if (l < x && x < r && t < y && y < b) {
            return true;
        }
        return false;
    }
}
tv.setFocusable(true);
tv.setFocusableInTouchMode(true);
tv.requestFocus();

3.设置Android studio中局部变量的颜色值

Paste_Image.png

4. Mac中设置adb环境变量

在mac系统下打开终端,输入:
touch .bash_profile
open -e .bash_profile
这样会弹出一个“.bash_profile”文件.
在弹出的文件中,写入platform-tools路径:
export PATH=${PATH}:/Users/zhangshuliang/Library/Android/sdk/platform-tools
关闭文件,并执行命令:source .bash_profile,保存文件的更改。

5.Dialog的下拉和上弹动画

 private void showBottomDialog() {
        View contentView = View.inflate(this, R.layout.dialog_bottom, null);
        TextView tvTakePhone = (TextView) contentView.findViewById(R.id.tv_take_phone);
        TextView tvSelctGallery = (TextView) contentView.findViewById(R.id.tv_select_gallery);
        TextView cancle = (TextView) contentView.findViewById(R.id.tv_cancle);
        tvTakePhone.setOnClickListener(this);
        tvSelctGallery.setOnClickListener(this);
        cancle.setOnClickListener(this);
        dialog = new Dialog(this, R.style.BottomDialog);
        dialog.setContentView(contentView);
        dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
        dialog.getWindow().setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
        dialog.setCanceledOnTouchOutside(true);
        dialog.show();
}
<style name="BottomDialog" parent="Base.Theme.AppCompat.Light.Dialog">
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:windowAnimationStyle">@style/DialogAnimation</item>
</style>
<style name="DialogAnimation" parent="@android:style/Animation.Dialog">
        <item name="android:windowEnterAnimation">@anim/bottom_dialog_enter</item>
        <item name="android:windowExitAnimation">@anim/bottom_dialog_out</item>
</style>
//从顶部下拉
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="500"
    android:interpolator="@android:anim/linear_interpolator"
    android:fromYDelta="-100%p"
    android:toYDelta="0">
</translate>
//顶部上移隐藏
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="500"
    android:fromYDelta="0"
    android:interpolator="@android:anim/linear_interpolator"
    android:toYDelta="-100%p">
</translate>
//底部弹起
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="300"
    android:interpolator="@android:anim/accelerate_interpolator"
    android:fromYDelta="100%"
    android:toYDelta="0%">
</translate>
//底部隐藏
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="300"
    android:fromYDelta="0%"
    android:interpolator="@android:anim/accelerate_interpolator" 
    android:toYDelta="100%">
</translate>
上一篇 下一篇

猜你喜欢

热点阅读