android – RemoveAllViews不删除视图

前端之家收集整理的这篇文章主要介绍了android – RemoveAllViews不删除视图前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我尝试删除线性布局的所有子视图但没有删除任何东西,奇怪的是相同的代码在另一个应用程序中工作.以下是每当选择选项卡时填充choiceHolder的方法的示例代码(我删除所有视图并标记所选视图并根据它填充:
  1. /** a method to fill the upper bar where we choose the {@link CategoriesMyBox}
  2. * @param category
  3. */
  4. private void fillNavigationBar( CategoriesGetter category) {
  5. TextView categoryTxt = new TextView(getActivity());
  6. // categoryTxt.setAllCaps(true);
  7. LinearLayout.LayoutParams txtParams;
  8. if (category.isSelected() /*|| (category.getId_categorie()==0 && allselected)*/) {
  9. txtParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
  10. txtParams.gravity = Gravity.CENTER;
  11. categoryTxt.setGravity(Gravity.CENTER);
  12. categoryTxt.setTextSize(categoryTxt.getTextSize());
  13. txtParams.setMargins(10,10,0);
  14. categoryTxt.setPadding(5,5,5);
  15. if (category.getId_categorie() == 0) {
  16. categoryTxt.setText(getResources().getString(R.string.all_Boxs));
  17. }else {
  18. categoryTxt.setText(category.getName_categorie());
  19. }
  20. categoryTxt.setTextColor(Color.GREEN);
  21. categoryTxt.setBackgroundDrawable(getResources().getDrawable(R.drawable.back_categories_selected));
  22. // categoryTxt.setBackgroundColor(Color.parseColor("#E3E8E6"));
  23. categoryTxt.setTag(category);
  24.  
  25.  
  26. }else {
  27.  
  28. txtParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
  29. txtParams.setMargins(10,0);
  30. categoryTxt.setGravity(Gravity.CENTER);
  31. categoryTxt.setPadding(5,5);
  32. txtParams.gravity = Gravity.CENTER;
  33. if (category.getId_categorie() == 0) {
  34. categoryTxt.setText(getResources().getString(R.string.all_Boxs));
  35. }else {
  36. categoryTxt.setText((category.getName_categorie()));
  37. }
  38. categoryTxt.setTextColor(Color.GRAY);
  39. categoryTxt.setBackgroundDrawable(getResources().getDrawable(R.drawable.back_categories));
  40. // categoryTxt.setBackgroundColor(Color.parseColor("#777777"));
  41. categoryTxt.setTag(category);
  42. }
  43. choiceHolder.addView(categoryTxt,txtParams);
  44. categoryTxt.setOnClickListener(new OnClickListener() {
  45.  
  46. @Override
  47. public void onClick(View v) {
  48. CategoriesGetter cat = (CategoriesGetter)v.getTag();
  49. id_cat = cat.getId_categorie();
  50. for (int i = 0; i < categories.size(); i++) {
  51. categories.get(i).setSelected(false);
  52. }
  53. cat.setSelected(true);
  54. // choiceHolder.removeAllViews();
  55. /*for(int i=0; i<((ViewGroup)choiceHolder).getChildCount(); ++i) {
  56. View nextChild = ((ViewGroup)choiceHolder).getChildAt(i);
  57. choiceHolder.removeView(nextChild);
  58. }*/
  59. while (((ViewGroup)choiceHolder).getChildCount() >0) {
  60. View nextChild = ((ViewGroup)choiceHolder).getChildAt(0);
  61. choiceHolder.removeView(nextChild);
  62. }
  63. // choiceHolder.removeAllViewsInLayout();
  64. for (int i = 0; i < categories.size(); i++) {
  65.  
  66. fillNavigationBar(categories.get(i));
  67. }
  68. callbackCategory.selectCategory(cat.getId_categorie());
  69.  
  70.  
  71.  
  72.  
  73.  
  74. }
  75. });
  76. }

choiceHolder是一个LinearLayout.

这是一张显示问题的图片

好吧我的所有应用程序的行为方式都相同,即使更新内部列表我仍然可以看到之前的列表.

解决方法

我发现这个问题的解决方案是从AndroidManifest中的活动中删除fullScreen主题标签,它是这样的:
  1. <application
  2. android:name="com.paperpad.myBox.ApplicationInit"
  3. android:allowBackup="true"
  4. android:icon="@drawable/ic_launcher"
  5. android:label="@string/app_name"
  6. android:theme="@style/AppTheme" >
  7. <activity
  8. android:name="com.paperpad.myBox.activities.SplashActivity"
  9. android:label="@string/app_name" >
  10. <intent-filter>
  11. <action android:name="android.intent.action.MAIN" />
  12.  
  13. <category android:name="android.intent.category.LAUNCHER" />
  14. </intent-filter>
  15. </activity>
  16.  
  17. <Meta-data
  18. android:name="com.crashlytics.ApiKey"
  19. android:value="023e7fe8a4a93f93ffe7510201929d081b125313" />
  20.  
  21. <activity
  22. android:name="com.paperpad.myBox.activities.BoxsMainActivity"
  23. android:configChanges="orientation|keyboardHidden|screenSize"
  24. android:label="@string/title_activity_Boxs_main"
  25. android:theme="@style/FullscreenTheme" >
  26. </activity>
  27. <activity
  28. android:name="com.paperpad.myBox.LoginActivity"
  29. android:label="@string/title_activity_login"
  30. android:windowSoftInputMode="adjustResize|stateVisible" >
  31. </activity>
  32. </application>

从活动BoxsMainActivityall中删除android:theme =“@ style / FullscreenTheme”.希望这有助于某人……

猜你在找的Android相关文章