在Android的锯齿型的ListView [英] Zigzag type of Listview in android

查看:208
本文介绍了在Android的锯齿型的ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要的ListView在这样的android

I want to make ListView in android like this

这是有可能在iPhone,在iPhone,他们习惯称之为圆视图

this is possible in iPhone ,in iPhone they used to call it Circle view

推荐答案

也可以使用xml.jst u需要膨胀的RowLayout然后添加填充到其视图。
下面code正确执行

It also possible using xml.jst u need to inflate rowLayout then add "Padding" to its view. The below code execute properly

请尝试以下code ..

Please try the below code..

public class MainActivity  extends ListActivity {
/** Called when the activity is first created. */
ListView lv;
int [] arr={20,40,60,80,80,60,40,20};


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    lv=getListView();
    CustomAdapter adapter=new CustomAdapter(this, arr);
    lv.setAdapter(adapter);

}

在下面的customAdapter getview方法写。改变数组按照您的要求。

write below getview method in your customAdapter. change the array as per your requirement

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

    LinearLayout ll = new LinearLayout(context);
    LinearLayout llInside = new LinearLayout(context);

    ll.setLayoutParams(new ListView.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT));
    llInside.setLayoutParams(new ListView.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    TextView tv = new TextView(context);
    tv.setLayoutParams(new ListView.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT));
    tv.setText("this is textbview");
    tv.setTextColor(Color.RED);
    tv.setLayoutParams(new ListView.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT));


    llInside.addView(tv);       


     //the padding is set here dynamically

    int rem = position % 8;
    Log.d("" + rem, "" + rem);
    llInside.setPadding(img[rem], 0, 0,0 );   

    ll.addView(llInside);
    return ll;
}

输出

Output

这篇关于在Android的锯齿型的ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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