特定设备上的九补丁背景问题

问题描述 投票:0回答:1

我将下面显示的9-patch图像test.9.png设置为视图的背景,然后将填充重置为0。

正如预期的那样,我的Nexus 4与Android 4.4.4的结果是对称的,但在我的华为G6-L11 4.3上我得到了如下所示的结果,即图像不是以对称的方式水平延伸。

我做错了还是错误?

test.hml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

</LinearLayout>

test fragment.Java

public class TestFragment extends Fragment {
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                 Bundle savedInstanceState) {

        return inflater.inflate(R.layout.test, container, false);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        view.setBackgroundResource(R.drawable.test);
        view.setPadding(0,0,0,0);
    }
}

test.9.png(6x4像素)

预期结果(Nexus 4,Android 4.4.4)

错误的结果(华为G6-L11,Android 4.3)

android nine-patch
1个回答
1
投票

将test.9.png添加到res/drawable-nodpi文件夹中

© www.soinside.com 2019 - 2024. All rights reserved.