GVKun编程网logo

循环浏览Android视图的所有子视图?(android 循环显示图片)

7

如果您对循环浏览Android视图的所有子视图?感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于循环浏览Android视图的所有子视图?的详细内容,我们还将为您解答andro

如果您对循环浏览Android视图的所有子视图?感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于循环浏览Android视图的所有子视图?的详细内容,我们还将为您解答android 循环显示图片的相关问题,并且为您提供关于android – GridView按位置获取视图,第一个子视图不同、android – 单击后获取动态创建的子视图的位置、android – 周视图和日视图的日历活动、android – 在其他视图的背景中显示视图?的有价值信息。

本文目录一览:

循环浏览Android视图的所有子视图?(android 循环显示图片)

循环浏览Android视图的所有子视图?(android 循环显示图片)

我正在为Android开发游戏.为了帮助实现它,我的想法是创建一个视图的子类.然后我会插入此类的几个实例作为主视图的子项.每个实例都会处理它被按下的时间(通过OnTouchListener).

我现在遇到的问题是如何遍历所有这些子视图,以便我可以读取它们的状态并处理它们? (即,当他们都达到某种状态时,应该发生一些事情).

或者是否有更好的方法可以在屏幕上显示多个响应触摸的对象以及我可以检查其状态?

解决方法:

@jqpubliq是对的但是如果你真的想要浏览所有的视图,你可以简单地使用ViewGroup中的getChildCount()和getChildAt()方法.一个简单的递归方法将完成剩下的工作.

android – GridView按位置获取视图,第一个子视图不同

android – GridView按位置获取视图,第一个子视图不同

Android GridView非常有趣,它重用了子视图.向上滚动的那些从底部返回.因此,GridView没有任何方法可以通过其位置获取子视图.但我真的需要通过它的立场来看待并做一些工作.所以要做到这一点,我创建了一个SparseArray并根据它们在BaseAdapter的getView中的位置放置了视图.
SparseArray<View> ViewArray = new SparseArray<View>();

public View getView(int position,View convertView,ViewGroup parent) {
    View view = convertView;    
    if (view == null)
       view = li.inflate(layoutID,null);
    ViewArray.put(position,view);
}

现在,我可以通过他们的位置获得所有可见的视图.一切都很完美,但在某些设备中,第一个子视图(位置0)与数组中的视图不同.我记录了getView,发现对于位置0,getView被多次调用,每次都使用不同的视图设置数组.我不知道为什么GridView多次为位置0调用getView,而这只发生在少数设备上.有解决方案吗

解决方法

在阅读了getPositionForView的源代码之后,我已经在自己的GridView中编写了这个方法,完全由API 18完成
public View GetViewByPosition(int position) {
    int firstPosition = this.getFirstVisiblePosition();
    int lastPosition = this.getLastVisiblePosition();

    if ((position < firstPosition) || (position > lastPosition))
        return null;

    return this.getChildAt(position - firstPosition);
}

android – 单击后获取动态创建的子视图的位置

android – 单击后获取动态创建的子视图的位置

我根据列表的大小动态扩充布局.现在每当我点击动态视图时,我必须获得点击子视图的位置.我正在尝试这段代码,但运气不好……

    LinearLayout layoutViewDealsList = (LinearLayout) view.findViewById(R.id.baseLinearLayoutSiteHistory);
    txtViewNoDeals = (TextView) view.findViewById(R.id.txtViewNoDeals);

    if(dealsList != null && dealsList.size() > 0) {
        for(int index = 0; index < dealsList.size(); index++) {
            txtViewNoDeals.setVisibility(View.GONE);
            LayoutInflater inflater = (LayoutInflater) profileActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            layoutView = inflater.inflate(R.layout.deal_row, null);

            txtViewDealsPrice = (TextView) layoutView.findViewById(R.id.txtViewDealPrice);  
            txtViewDealsTitle = (TextView) layoutView.findViewById(R.id.txtViewDealTitle);
            txtViewDealsDescription = (TextView) layoutView.findViewById(R.id.txtViewDealDescription);
            txtViewDealsBuyer = (TextView) layoutView.findViewById(R.id.txtViewDealBuyer);
            txtViewDealsDate = (TextView) layoutView.findViewById(R.id.txtViewDealDate);

            txtViewDealsPrice.setText("Price: $" + dealsList.get(index).getDeal_amount());
            txtViewDealsTitle.setText(dealsList.get(index).getTitle());
            txtViewDealsDescription.setText(dealsList.get(index).getDesc());

            layoutViewDealsList.addView(layoutView);
            int position = layoutViewDealsList.indexOfChild(layoutView);
            layoutViewDealsList.setTag(position);
            appDelegate.setDealsList(dealsList);
        }
    } 


    layoutViewDealsList.setonClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            int position  = (Integer) v.getTag();//layoutViewDealsList.indexOfChild(layoutView);
            Toast.makeText(profileActivity, ""+position, Toast.LENGTH_SHORT).show();


        }
    });

我无法知道我在哪里做错了.

解决方法:

您需要在layoutView内部循环中应用onClickListener.

LinearLayout layoutViewDealsList = (LinearLayout) view.findViewById(R.id.baseLinearLayoutSiteHistory);
txtViewNoDeals = (TextView) view.findViewById(R.id.txtViewNoDeals);

if(dealsList != null && dealsList.size() > 0) {
    for(int index = 0; index < dealsList.size(); index++) {
        txtViewNoDeals.setVisibility(View.GONE);
        LayoutInflater inflater = (LayoutInflater) profileActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        layoutView = inflater.inflate(R.layout.deal_row, null);

    txtViewDealsPrice = (TextView) layoutView.findViewById(R.id.txtViewDealPrice);  
    txtViewDealsTitle = (TextView) layoutView.findViewById(R.id.txtViewDealTitle);
    txtViewDealsDescription = (TextView) layoutView.findViewById(R.id.txtViewDealDescription);
    txtViewDealsBuyer = (TextView) layoutView.findViewById(R.id.txtViewDealBuyer);
    txtViewDealsDate = (TextView) layoutView.findViewById(R.id.txtViewDealDate);

    txtViewDealsPrice.setText("Price: $" + dealsList.get(index).getDeal_amount());
    txtViewDealsTitle.setText(dealsList.get(index).getTitle());
    txtViewDealsDescription.setText(dealsList.get(index).getDesc());

    layoutViewDealsList.addView(layoutView);
    int position = layoutViewDealsList.indexOfChild(layoutView);
    layoutViewDealsList.setTag(position);
    appDelegate.setDealsList(dealsList);

layoutView.setonClickListener(this); <--------------- setonClickListener
}

}

你的onClick()看起来像……

@Override
        public void onClick(View v) {

            int position  = (Integer) v.getTag();
            Toast.makeText(profileActivity, ""+position, Toast.LENGTH_SHORT).show();


        }

android – 周视图和日视图的日历活动

android – 周视图和日视图的日历活动

我想创建一个包含WeekView和DayView功能的日历应用.

请给我一些建议.我搜索了很多示例项目,但没有一个正在运行:请提供给我任何示例项目.

我需要的屏幕是:

解决方法

通过在日食中查看,查看 here是示例代码.它的开源.

android – 在其他视图的背景中显示视图?

android – 在其他视图的背景中显示视图?

我想在图像视图的背景中显示进度条是否可能?
请帮忙?

解决方法:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background"
      android:drawable="@drawable/custom_background1" />
<item android:id="@android:id/secondaryProgress">
    <clip android:drawable="@drawable/custom_background2" />
</item>
<item android:id="@android:id/progress">
    <clip android:drawable="@drawable/custom_background3" />
</item>
</layer-list>

如上所述在drawalbe中创建一个xml文件,并在layout.xml中使用

android:progressDrawable="@drawable/music_volume_seekbar_style"

你的意思是?

关于循环浏览Android视图的所有子视图?android 循环显示图片的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于android – GridView按位置获取视图,第一个子视图不同、android – 单击后获取动态创建的子视图的位置、android – 周视图和日视图的日历活动、android – 在其他视图的背景中显示视图?的相关信息,请在本站寻找。

本文标签: