Android XML形状drawable正在阻碍我的用户界面

时间:2015-10-15 18:45:57

标签: android xml android-drawable android-shape

我正在使用XML drawables并使用图层动态地将它们叠加在彼此之上。每次用户点击按钮时,它都覆盖另一个图像。问题是,一旦我有五或十层这个特定的XML drawable,那么UI想要锁定。这是可绘制的:

<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <rotate
            android:fromDegrees="247.5"
            android:toDegrees="247.5"
            android:pivotX="50%"
            android:pivotY="50%">
            <shape android:shape="oval">
                <size
                    android:width="800dp"
                    android:height="800dp"/>
                <stroke
                    android:dashWidth="235.6dp"
                    android:dashGap="5000.01dp"
                    android:width="200dp"
                    android:color="#c2272d" />
            </shape>
        </rotate>
    </item>
    <item android:top="0dp" android:bottom="0dp" android:left="0dp" android:right="0dp">
        <rotate
            android:fromDegrees="247.5"
            android:toDegrees="247.5"
            android:pivotX="50%"
            android:pivotY="50%">
            <shape android:shape="oval">
                <size
                    android:width="800dp"
                    android:height="800dp"/>
                <stroke
                    android:dashWidth="290.6dp"
                    android:dashGap="5000.01dp"
                    android:width="60dp"
                    android:color="#767171" />
            </shape>
        </rotate>
    </item>
</layer-list>

这是我用来显示和更新的代码:

public class ShotMagFragment extends Fragment implements DataDelegate, View.OnClickListener{

    private ImageView mainImage;
    private ArrayList<Drawable> layers = new ArrayList<>();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_shot_mag, container, false);
        View simulateBtn = view.findViewById(R.id.simulateBtn);
        simulateBtn.setOnClickListener(this);
        mainImage = (ImageView)view.findViewById(R.id.mainImage);
        return view;
    }


    public void displayNewImage() {
        Random r = new Random();
        int number = 1 + (20 - 20) * r.nextInt();
        Drawable d = getResources().getDrawable(getResources().getIdentifier("mag_shade" + number, "drawable", getContext().getPackageName()));
        layers.add(d);

        final LayerDrawable layerDrawable = new LayerDrawable(layers.toArray(new Drawable[layers.size()]));
        getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                mainImage.setImageDrawable(layerDrawable);
            }
        });
    }
    @Override
    public void onClick(View v) {
        displayNewImage();
    }
}

但是当我使用不同的XML drawable时,我没有得到相同的UI锁定问题:

<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:top="130dp" android:bottom="130dp" android:left="130dp" android:right="130dp">
        <rotate
            android:fromDegrees="247.5"
            android:toDegrees="247.5"
            android:pivotX="50%"
            android:pivotY="50%">
            <shape android:shape="oval">
                <size
                    android:width="540dp"
                    android:height="540dp"/>
                <stroke
                    android:dashWidth="212.0dp"
                    android:dashGap="5000.01dp"
                    android:width="4dp"
                    android:color="#fff" />
            </shape>
        </rotate>
    </item>
</layer-list>

修改 我在我的drawable引用旁边也得到了一个奇怪的错误图标。当我点击它时,它只是把我带到了drawable。我不知道这是否与我的问题有关,是否是真正的错误,或者只是一个通知。

error image

0 个答案:

没有答案