Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:在CustomView上滚动或调整画布大小_Android_Scrollview_Android Canvas - Fatal编程技术网

Android:在CustomView上滚动或调整画布大小

Android:在CustomView上滚动或调整画布大小,android,scrollview,android-canvas,Android,Scrollview,Android Canvas,我有一个自定义视图,其中有一个用圆圈和线条绘制的画布。我的问题是,一旦转移到平板电脑上,图像就会被裁剪,而不是真实的。有没有办法自动调整CustomView的大小和适应屏幕,甚至滚动图像。 一段代码: public class CustomView extends View { Paint pPaint; Paint cPaint; Paint textPaint; int w,h; int px=150,py=150; int cx=450,

我有一个自定义视图,其中有一个用圆圈和线条绘制的画布。我的问题是,一旦转移到平板电脑上,图像就会被裁剪,而不是真实的。有没有办法自动调整CustomView的大小和适应屏幕,甚至滚动图像。 一段代码:

public class CustomView extends View {

    Paint pPaint;
    Paint cPaint;
    Paint textPaint;

    int w,h;
    int px=150,py=150;
    int cx=450,cy=150;
    public CustomView(Context context, AttributeSet attrs) {
        super(context, attrs);


        pPaint=new Paint(); // pennello
        pPaint.setColor(Color.RED);  
        pPaint.setAntiAlias(true); 

        cPaint=new Paint(); // pennello
        cPaint.setColor(Color.CYAN);     
        cPaint.setAntiAlias(true);

        textPaint=new Paint(); // pennello
        textPaint.setColor(Color.BLACK);     
        textPaint.setAntiAlias(true);

    }



<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    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" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <com.abstractargument.CustomView
            android:id="@+id/customView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
    </LinearLayout>

</RelativeLayout>
公共类CustomView扩展了视图{
油漆;
油漆;
油漆;
int w,h;
int px=150,py=150;
int cx=450,cy=150;
公共自定义视图(上下文、属性集属性){
超级(上下文,attrs);
pPaint=new Paint();//pennello
pPaint.setColor(颜色为红色);
pPaint.setAntiAlias(真);
cPaint=new Paint();//pennello
cPaint.setColor(Color.CYAN);
cPaint.setAntiAlias(true);
textPaint=new Paint();//pennello
textPaint.setColor(Color.BLACK);
textPaint.setAntiAlias(true);
}

为什么不直接将线性布局设置为填充父视图?然后自定义视图也会有屏幕大小,因为它不起作用,我不理解相对布局是无用的,您可以将布局参数放在线性布局中,而忽略相对布局。然后,如Marko所说,将布局高度/宽度设置为匹配_如果只有一个子视图,“orientation=vertical”不会起任何作用。我做了您建议的更改,但结果没有更改。很遗憾,我可以用canvas设置ScrollView吗?