我怎样才能让图标上悬停布局,也可以点击 [英] How can i make icons hover on layout which will also be clickable

查看:154
本文介绍了我怎样才能让图标上悬停布局,也可以点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设计使用滚轮菜单栏的页面。车轮菜单栏圈非常好。但我想,当图标来在页面顶部衬板的布局,应该知道哪些图像徘徊。并应能点击。我写的算法

1)我希望把眼线布局在页面顶部

2),当图标(这是图片)来对这个衬垫布局应该能点击

3)这种布局应该知道哪些悬停按钮

** ** XML

 <?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:方向=垂直
    机器人:背景=@绘制/ cell_bg
    >    <的TextView
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:文字=你好,GAMA! />    <的LinearLayout
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =500dp
        机器人:方向=垂直
        机器人:背景=@绘制/ belirtec9_2bg
        机器人:paddingTop =10px的
    >    < com.digitalaria.gama.wheel.Wheel
        机器人:ID =@ + ID /轮
        机器人:paddingTop =10px的
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_gravity =中心/>    < / LinearLayout中>< / LinearLayout中>

... code

 包com.myproject.gama;进口java.util.Arrays中;进口com.digitalaria.gama.wheel.Wheel;
进口com.digitalaria.gama.wheel.WheelAdapter;进口android.app.Activity;
进口android.content.res.Resources;
进口android.graphics.drawable.Drawable;
进口android.os.Bundle;
进口android.view.View;
进口android.view.View.OnClickListener;
导入android.widget *。
进口android.view.View *。
进口android.widget.AdapterView.OnItemClickListener;
进口android.widget.AdapterView.OnItemSelectedListener;
进口android.widget.ImageButton;
进口android.widget.ImageView;进口android.util.Log;公共类SampleWheelActivity延伸活动{    私有静态最后弦乐TAG = SampleWheelActivity.class.getSimpleName();    私人车轮轮;
    公共WheelAdapter<适配器和GT;适配器;
    私人资源资源;
    公众诠释[]图标= {
         R.drawable.icon1,R.drawable.icon0,R.drawable.icon2};
    ImageView的吨;    @覆盖
    公共无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.main);        在里面();
    }    私人无效的init(){
        RES = getApplicationContext()getResources()。
        轮=(轮)findViewById(R.id.wheel);
        wheel.setItems(getDrawableFromData(图标));
        wheel.setWheelDiameter(400);
    }    @覆盖
    公共无效onResume(){
        //yöntem0
                字符串arrayStr = Arrays.toString(图标);
                的String [] = strArray新的String [] {} arrayStr;
        super.onResume();
    }    私人OnClickListener的onClick(){
         Toast.makeText(SampleWheelActivity.this,测试,Toast.LENGTH_SHORT).show();
        返回null;
    }    私人绘制对象[] getDrawableFromData(INT []数据){
        可绘制[] = RET新绘制对象[data.length]
        的for(int i = 0; I< data.length;我++){
            RET [I] = res.getDrawable(数据由[i]);
        }
        返回RET;
    }/ *无效onItemClick(WheelAdapter<>母公司,观景,INT位置,
            长ID){
        Log.d(TAGOnItemClick);
        Toast.makeText(getApplicationContext(),onItemClick,Toast.LENGTH_LONG).show();
    } * /}


解决方案

在您的初始化函数使用此code

  wheel.setItemClickEventAtSelectionPosition(假);wheel.setOnItemClickListener(新WheelAdapter.OnItemClickListener(){        @覆盖
        公共无效onItemClick(WheelAdapter<>母公司,观景,
                INT位置,长的id){
            // TODO自动生成方法存根}
});

I've designed a page using a wheel menu bar. Wheel menu bar circled very good. But I want to when icons come at liner layout on top of the page, it should be know which image is hovering. And it should be click able. I write algorithm

1) I want to put liner layout on top of the page

2) when icons(this are image) come on this liner layout it should be click able

3) this layout should know which button on hover

** 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>

...... code

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();
    }*/

}

解决方案

Use this code in your init function

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

}
});

这篇关于我怎样才能让图标上悬停布局,也可以点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆