新扩展的ListView高度可定制

新扩展的ListView高度可定制

本文介绍了新扩展的ListView高度可定制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要认识到类似的东西的图片:TITLE矩形使对象的列表,当我点击这些对象之一是开设了子菜单中的(那里有元素#1,2等)。该系统类似于一个可扩展的列表视图,而且更加个性化。

你怎么认为要认识到?我怎样才能做一个动画的子菜单的崩溃?如果我设置走了,然后子菜单时的onClick上的头衔,我设置的能见度=可视突然出现......我想要的东西的动画在Android的风格。

你有什么建议怎么样?我想实现一个对象每次我需要认识到类似的东西时候istantiate。

解决方案

  CustomListViewDemo.java

公共类CustomListViewDemo扩展ListActivity {
  私人EfficientAdapter ADAP;

  私有静态字符串[]数据=新的String [] {0,1,2,3,4};

  @覆盖
  公共无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    的setContentView(R.layout.main);
    ADAP =新EfficientAdapter(本);
    setListAdapter(ADAP);
  }

  @覆盖
  保护无效onListItemClick(ListView的L,视图V,INT位置,长的id){
    // TODO自动生成方法存根
    super.onListItemClick(L,V,位置ID);
    Toast.makeText(这一点,点击 - +将String.valueOf(位置),Toast.LENGTH_SHORT).show();
  }

  公共静态类EfficientAdapter扩展了BaseAdapter实现过滤的{
    私人LayoutInflater mInflater;
    私人位图mIcon1;
    私人上下文的背景下;
    INT firstpos = 0;

    公共EfficientAdapter(上下文的背景下){
      //缓存的LayoutInflate避免询问,每次一个新的。
      mInflater = LayoutInflater.from(上下文);
      this.context =背景;
    }

    公共查看getView(最终诠释的立场,观点convertView,ViewGroup中父){

      ViewHolder持有人;

      如果(convertView == NULL){
        convertView = mInflater.inflate(R.layout.adaptor_content,NULL);

        持有人=新ViewHolder();
        holder.sp =(微调)convertView.findViewById(R.id.spinner1);

        holder.ArrayAdapter_sp =新ArrayAdapter(parent.getContext(),android.R.layout.simple_spinner_item,数据);
        holder.ArrayAdapter_sp.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

        holder.sp.setAdapter(holder.ArrayAdapter_sp);
        holder.sp.setOnItemSelectedListener(新OnItemSelectedListener()
        {
            私人诠释POS =位置;
            @覆盖
            公共无效onItemSelected(适配器视图<>为arg0,查看ARG1,
                    INT磷,长ARG3)
            {
                // TODO自动生成方法存根
                 Toast.makeText(背景下,选择微调+将String.valueOf(POS)+与价值ID+ P,Toast.LENGTH_SHORT).show();

            }

            @覆盖
            公共无效onNothingSelected(适配器视图<>为arg0)
            {
                // TODO自动生成方法存根

            }
        });




        convertView.setTag(保持器);
      } 其他 {

        支架=(ViewHolder)convertView.getTag();
      }


      返回convertView;
    }

    静态类ViewHolder
    {

        微调SP;
        ArrayAdapter ArrayAdapter_sp;

    }

    @覆盖
    公共过滤用getFilter(){
      // TODO自动生成方法存根
      返回null;
    }

    @覆盖
    众长getItemId(INT位置){
      // TODO自动生成方法存根
      返回0;
    }

    @覆盖
    公众诠释getCount将(){
      // TODO自动生成方法存根
      返回data.length;
    }

    @覆盖
    公共对象的getItem(INT位置){
      // TODO自动生成方法存根
      返回数据[位置]
    }

  }

}

-------------------------------------------------- --------------------------------
                        adaptor_content.xml

< XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@ + ID /订单项
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:重力=center_vertical>

    <微调
        机器人:ID =@ + ID / spinner1
        机器人:layout_width =314dp
        机器人:layout_height =WRAP_CONTENT/>

< / LinearLayout中>


-------------------------------------------------- ------------------------
                        main.xml中

< XML版本=1.0编码=UTF-8&GT?;

< RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_height =FILL_PARENT机器人:layout_width =FILL_PARENT
    >

    <的ListView
        机器人:ID =@ + ID / Android的:清单
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =FILL_PARENT
        机器人:layout_marginBottom =60dip
        机器人:layout_marginTop =10dip
        机器人:cacheColorHint =#00000000
        机器人:drawSelectorOnTop =FALSE/>

< / RelativeLayout的>
 

I need to realize something like that in the picture:"TITLE" rectangle makes a list of object and when I click on one of these objects is opened a "sub menu" (where there are ELEMENT #1, 2 etc.). The system is similar to a expandable listview, but more customizable.

How do you suggest to realize that?How can i do an animation for the collapse of the sub menu? If I set sub menu with gone and then when onClick on title I set that with visibility=visible suddenly appears...I'd like something of animated in Android style.

What do you suggest? I was thinking to realize an object to istantiate each time i need to realize something like that.

解决方案
                    CustomListViewDemo.java

public class CustomListViewDemo extends ListActivity {
  private EfficientAdapter adap;

  private static String[] data = new String[] { "0", "1", "2", "3", "4" };

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.main);
    adap = new EfficientAdapter(this);
    setListAdapter(adap);
  }

  @Override
  protected void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub
    super.onListItemClick(l, v, position, id);
    Toast.makeText(this, "Click-" + String.valueOf(position), Toast.LENGTH_SHORT).show();
  }

  public static class EfficientAdapter extends BaseAdapter implements Filterable {
    private LayoutInflater mInflater;
    private Bitmap mIcon1;
    private Context context;
    int firstpos=0;

    public EfficientAdapter(Context context) {
      // Cache the LayoutInflate to avoid asking for a new one each time.
      mInflater = LayoutInflater.from(context);
      this.context = context;
    }

    public View getView(final int position, View convertView, ViewGroup parent) {

      ViewHolder holder;

      if (convertView == null) {
        convertView = mInflater.inflate(R.layout.adaptor_content, null);

        holder = new ViewHolder();
        holder.sp = (Spinner) convertView.findViewById(R.id.spinner1);

        holder.ArrayAdapter_sp = new ArrayAdapter(parent.getContext(),android.R.layout.simple_spinner_item,data);
        holder.ArrayAdapter_sp.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

        holder.sp.setAdapter( holder.ArrayAdapter_sp);
        holder.sp.setOnItemSelectedListener(new OnItemSelectedListener()
        {
            private int pos = position;
            @Override
            public void onItemSelected(AdapterView<?> arg0, View arg1,
                    int p, long arg3)
            {
                // TODO Auto-generated method stub
                 Toast.makeText(context, "select spinner " + String.valueOf(pos)+" with value ID "+p, Toast.LENGTH_SHORT).show();

            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0)
            {
                // TODO Auto-generated method stub

            }
        });




        convertView.setTag(holder);
      } else {

        holder = (ViewHolder) convertView.getTag();
      }


      return convertView;
    }

    static class ViewHolder
    {

        Spinner sp;
        ArrayAdapter ArrayAdapter_sp;

    }

    @Override
    public Filter getFilter() {
      // TODO Auto-generated method stub
      return null;
    }

    @Override
    public long getItemId(int position) {
      // TODO Auto-generated method stub
      return 0;
    }

    @Override
    public int getCount() {
      // TODO Auto-generated method stub
      return data.length;
    }

    @Override
    public Object getItem(int position) {
      // TODO Auto-generated method stub
      return data[position];
    }

  }

}

----------------------------------------------------------------------------------
                        adaptor_content.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/lineItem"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center_vertical" >

    <Spinner
        android:id="@+id/spinner1"
        android:layout_width="314dp"
        android:layout_height="wrap_content" />

</LinearLayout>


--------------------------------------------------------------------------
                        main.xml

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="fill_parent" android:layout_width="fill_parent"
    >

    <ListView
        android:id="@+id/android:list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginBottom="60dip"
        android:layout_marginTop="10dip"
        android:cacheColorHint="#00000000"
        android:drawSelectorOnTop="false" />

</RelativeLayout>

这篇关于新扩展的ListView高度可定制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 00:53