在android中的zoomview中有一个可点击的按钮

时间:2013-12-13 07:28:25

标签: android

我想在zoomview中点击按钮。但我的问题是当我设置视图时   zoomview然后按钮没有响应点击,我在这一点卡住了任何帮助   是apreciated

我的代码是

public class SongsActivity extends Activity {
ImageView imvw;

DrawView drawView;

ImageView imageView;



View dv;


RelativeLayout rdown;

private static final float MIN_ZOOM = 1f, MAX_ZOOM = 1f;


Matrix matrix = new Matrix();
Matrix savedMatrix = new Matrix();


static final int NONE = 0;
static final int DRAG = 1;
static final int ZOOM = 2;
private static final RelativeLayout New = null;
int mode = NONE;


PointF start = new PointF();
PointF mid = new PointF();
float oldDist = 1f;
RelativeLayout main_container;
private ZoomView zoomView;
Button BtnWelcome;


public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.songs_layout);
    try{
    imvw = (ImageView) findViewById(R.id.imageView1);

    View v = ((LayoutInflater)      

            getSystemService(Context.LAYOUT_INFLATER_SERVICE))
            .inflate(R.layout.songs_layout, null, false);



    BtnWelcome = (Button) findViewById(R.id.button4);

     v.setLayoutParams(new RelativeLayout.LayoutParams(
     LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    main_container = (RelativeLayout) findViewById(R.id.Map);




    zoomView = new ZoomView(this);
    zoomView.addView(v);



    main_container.addView(zoomView);

    //BtnWelcome.bringToFront();

    BtnWelcome.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent = new Intent(SongsActivity.this,
                    Wavepointsactivity.class);
            intent.putExtra("Welcome", "Welcome");
            startActivity(intent);
        }
    });


}catch (Exception e) {
    // TODO: handle exception
}
}


}

我的xml是

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<!-- Screen Design for the SONGS -->

<RelativeLayout
    android:id="@+id/tabconteffnt"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_gravity="top"
    android:background="#2E2E2E"
    android:gravity="center_horizontal" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:text="Cedar Breaks-Map"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="@android:color/white" />
</RelativeLayout>

<RelativeLayout
    android:id="@+id/Map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="top"
    android:gravity="center_horizontal" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_marginBottom="70dp"
        android:scaleType="fitXY"
        android:src="@drawable/map" />

    <Button
        android:id="@+id/button4"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/button3"
        android:layout_marginRight="37dp" />

    <Button
        android:id="@+id/button5"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="40dp"
        android:layout_height="60dp"
        android:layout_below="@+id/button4"
        android:layout_toLeftOf="@+id/button4"
        android:text="Button" />

    <Button
        android:id="@+id/button6"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_alignLeft="@+id/button5"
        android:layout_below="@+id/button5"
        android:layout_marginTop="18dp"
        android:text="Button" />

    <Button
        android:id="@+id/button7"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_below="@+id/button6"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="21dp"
        android:text="Button" />

    <Button
        android:id="@+id/button3"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_below="@+id/button2" />

    <Button
        android:id="@+id/button11"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignTop="@+id/button9"
        android:text="Button" />

    <Button
        android:id="@+id/button10"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_above="@+id/button9"
        android:layout_alignRight="@+id/button11"
        android:text="Button" />

    <Button
        android:id="@+id/button8"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_alignBaseline="@+id/button10"
        android:layout_alignBottom="@+id/button10"
        android:text="Button" />

    <Button
        android:id="@+id/button9"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_alignBaseline="@+id/button7"
        android:layout_alignBottom="@+id/button7"
        android:layout_alignLeft="@+id/button8"
        android:text="Button" />

    <Button
        android:id="@+id/button2"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_alignLeft="@+id/button3" />

    <RelativeLayout
        android:id="@+id/view1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignBottom="@+id/imageView1"
        android:layout_alignLeft="@+id/view1" >
    </RelativeLayout>
</RelativeLayout>

</LinearLayout>

1 个答案:

答案 0 :(得分:0)

初始化你的id有一些问题。在你的xml中没有声明按钮。所以它是一个空指针异常。

BtnWelcome = (Button) findViewById(R.id.button1);

给出正确的按钮ID。它可以解决错误..