如何使图标悬停在布局上,也可以点击

时间:2014-03-06 21:08:18

标签: android

我使用滚轮菜单栏设计了一个页面。轮式菜单栏圈出非常好。但是我希望当图标出现在页面顶部的线条布局上时,应该知道哪个图像正在悬停。它应该是可点击的。我写算法

1)我想在页面顶部放置衬垫布局

2)当图标(这是图像)出现在这个班轮布局上时,它应该是可点击的

3)此布局应该知道悬停在哪个按钮

** xml **

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

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Hello, GAMA!" />

    <LinearLayout 
        android:layout_width="wrap_content"
        android:layout_height="500dp"
        android:orientation="vertical" 
        android:background="@drawable/belirtec9_2bg"
        android:paddingTop="10px"
    >

    <com.digitalaria.gama.wheel.Wheel
        android:id="@+id/wheel"
        android:paddingTop="10px" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"/>

    </LinearLayout>

</LinearLayout>

......代码

package com.myproject.gama;

import java.util.Arrays;

import com.digitalaria.gama.wheel.Wheel;
import com.digitalaria.gama.wheel.WheelAdapter;

import android.app.Activity;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;
import android.view.View.*;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ImageButton;
import android.widget.ImageView;

import android.util.Log;

public class SampleWheelActivity extends Activity {

    private static final String TAG = SampleWheelActivity.class.getSimpleName();

    private Wheel wheel;
    public WheelAdapter<Adapter> adapter;
    private Resources res; 
    public int[] icons = { 
         R.drawable.icon1, R.drawable.icon0 , R.drawable.icon2};
    ImageView t;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        init();
    }

    private void init() {
        res = getApplicationContext().getResources();
        wheel = (Wheel) findViewById(R.id.wheel);       
        wheel.setItems(getDrawableFromData(icons));
        wheel.setWheelDiameter(400);


    }

    @Override
    public void onResume(){


        //yöntem0
                String arrayStr = Arrays.toString (icons);
                String[] strArray = new String[] {arrayStr};


        super.onResume();
    }



    private OnClickListener onClick() {
         Toast.makeText(SampleWheelActivity.this, "test", Toast.LENGTH_SHORT).show();
        return null;
    }



    private Drawable[] getDrawableFromData(int[] data) {
        Drawable[] ret = new Drawable[data.length];
        for (int i = 0; i < data.length; i++) {
            ret[i] = res.getDrawable(data[i]);
        }
        return ret;
    }

/*  void onItemClick(WheelAdapter<?> parent, View view, int position,
            long id){
        Log.d(TAG,"OnItemClick");
        Toast.makeText(getApplicationContext(), "onItemClick", Toast.LENGTH_LONG).show();
    }*/

}

2 个答案:

答案 0 :(得分:0)

您可以在布局中的每个按钮或视图上设置onclicklistener。

wheel.setOnClickListener(new View.OnClickListener(){

                @Override
                public void onClick(final View v) {
});

答案 1 :(得分:0)

在init函数中使用此代码

wheel.setItemClickEventAtSelectionPosition(false);

wheel.setOnItemClickListener(new WheelAdapter.OnItemClickListener() {

        @Override
        public void onItemClick(WheelAdapter<?> parent, View view,
                int position, long id) {
            // TODO Auto-generated method stub

}
});