android-discuss icon indicating copy to clipboard operation
android-discuss copied to clipboard

谈一下你在屏幕适配上遇到得问题?

Open gmx1234 opened this issue 11 years ago • 8 comments

gmx1234 avatar Apr 08 '15 08:04 gmx1234

安卓版本不同,还有屏幕分辨率的不同,最好用dp不要用sp。

freyh avatar Apr 10 '15 03:04 freyh

在默认情况下,sp=dp,但是系统字体变大sp会变大,到底要不要彻底放弃sp呢?

SeniorZhai avatar Apr 10 '15 08:04 SeniorZhai

代码中dp换算成px的值和直接在layout里面设置dp得到的值并不相等

leonlbh4 avatar Apr 10 '15 13:04 leonlbh4

魅族的sbbar需要单独适配

UserWang avatar Apr 10 '15 14:04 UserWang

若要兼容2.X版本的手机,布局的父组件式FrameLayout或者RelativeLayout,则子View最好不要使用Margin来调整位置,因为会失效,如HTC的G5,所以可以使用Padding来调整布局,因此有时候不可避免地多嵌套了一层布局。

benhero avatar Apr 10 '15 18:04 benhero

这是我经常面试问的问题。 最好的做法是自定义一套view,重写onFinishInflate函数。

philofly avatar May 05 '15 09:05 philofly

@philofly 能不能具体说下思路,重写是为了解决什么问题

ZhaoKaiQiang avatar May 05 '15 10:05 ZhaoKaiQiang

public class ScaleView extends View {

public ScaleView(Context context) {
    super(context);
}

public ScaleView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public ScaleView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

@Override
protected void onFinishInflate() {
    super.onFinishInflate();
    try {
        这里根据屏幕对view缩放
    } catch (Exception e) {
        e.printStackTrace();
    }
}

}

philofly avatar May 28 '15 11:05 philofly