[英]Scaling a background image in android for a custom view (seekArc)
I have an image: 我有一张图片:
This image is being set as the background for the seekArc (a circularized seekBar, found here ) 该图像被设置为seekArc的背景(圆形的seekBar,在此处找到)
The problem is, when I set the image I have made to the background of the seekArc view; 问题是,当我设置图像时,将其设置为seekArc视图的背景。 it extends past the actual arc of the seekArc; 它延伸超过seekArc的实际弧线; as seen with this 正如这个看到的
XML Code: XML代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:seekarc="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<com.triggertrap.seekarc.SeekArc
android:id="@+id/SeekArc1"
android:layout_width="500dp"
android:layout_height="500dp"
android:layout_alignBottom="@+id/hometemp"
android:layout_alignParentRight="true"
android:background="@drawable/largepower"
android:padding="85dp"
seekarc:arcWidth="3dp"
seekarc:max="100"
seekarc:rotation="180"
seekarc:startAngle="30"
seekarc:sweepAngle="300"
seekarc:touchInside="true" />
<com.triggertrap.seekarc.SeekArc
android:id="@+id/SeekArc01"
android:layout_width="500dp"
android:layout_height="500dp"
android:layout_alignLeft="@+id/homepower"
android:layout_alignTop="@+id/SeekArc1"
android:padding="85dp"
seekarc:arcWidth="3dp"
seekarc:max="100"
seekarc:rotation="180"
seekarc:startAngle="30"
seekarc:sweepAngle="300"
seekarc:touchInside="true" />
<ProgressBar
android:id="@+id/hometemp"
style="@style/tallerBarStyle"
android:layout_width="500dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:maxHeight="50dp" />
<Switch
android:id="@+id/homepower"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignTop="@+id/SeekArc01"
android:text="Power" />
</RelativeLayout>
fragment code: 片段代码:
homeFragmentView = viewInflation.inflate(R.layout.homefragment_page,
container, false);
temp = (ProgressBar) homeFragmentView.findViewById(R.id.hometemp);
power = (Switch) homeFragmentView.findViewById(R.id.homepower);
s1 = (SeekArc) homeFragmentView.findViewById(R.id.SeekArc1);
s2 = (SeekArc) homeFragmentView.findViewById(R.id.SeekArc01);
Resources res = homeFragmentView.getResources();
Drawable drawable = res.getDrawable(R.drawable.largepower);
if (drawable.equals(null)) {
Toast.makeText(getActivity().getBaseContext(), "NULL", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getActivity().getBaseContext(), "NOT NULL", Toast.LENGTH_LONG).show();
s1.setBackground(drawable);
}
What would be a good method about getting the seekArc to go around the image? 有什么好办法可以使seekArc遍历图像?
I solved this problem by creating a custom bitmap.xml file: 我通过创建一个自定义的bitmap.xml文件解决了这个问题:
<?xml version="1.0" encoding="utf-8"?>
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/small"
android:antialias="false"
android:dither="false"
android:filter="false"
android:gravity="center"
android:mipMap="false"
android:tileMode="disabled" />
and placing it within a new folder @drawable-nodpi that I created in my res. 并将其放置在我在res中创建的新文件夹@ drawable-nodpi中。
Then I referred to a manually-scaled image of the size I needed. 然后,我参考了需要的尺寸的手动缩放图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.