2017-09-13 67 views
0

我一直在努力弄清楚这个奇怪的错误一天半。每当我点击一个EditText是一个ExpandableListView的孩子,画面被遮挡,使得用户无法看到的是什么类型的,如下面的GIF:\ n https://giant.gfycat.com/GenuineUnluckyHyrax.mp4点击EditText里面的屏幕会变成背景颜色ExpandableListView

我开始挖成分层结构视图,看看有什么可以做这个,这里是它的屏幕截图: https://i.imgur.com/B4kkHv7.png

对我来说,它看起来像工具栏了顶部向下延伸到覆盖屏幕,这是奇怪的,因为它没有这样做对其他含有EditText小工具的活动。我已检查父视图是否使用“wrap_content”代替“match_parent”,而我的DrawerLayout必须使用match_parent。下面是该活动的布局代码:

<!-- This DrawerLayout has two children at the root --> 
<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <!-- This LinearLayout represents the contents of the screen --> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 


     <!-- The ActionBar displayed at the top --> 
     <include 
      layout="@layout/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

     <!-- The main content view where fragments are loaded --> 
     <FrameLayout 
      android:id="@+id/flContent" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 
      <RelativeLayout 
       android:id="@+id/rlcontent" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:focusable="true" 
       android:focusableInTouchMode="true"> 

       <!--SideBar views --> 
       <RelativeLayout 
        android:layout_width="350dp" 
        android:layout_height="match_parent" 
        android:background="@color/sidebarColor"> 
        <ExpandableListView 
         android:id="@+id/qwedit_sidebar_elv" 
         android:layout_width="match_parent" 
         android:layout_height="match_parent" 
         android:indicatorLeft="? 
android:attr/expandableListPreferredItemIndicatorLeft" 
         android:divider="@color/colorPrimary" 
         android:dividerHeight="0.5dp"> 
        </ExpandableListView> 
       </RelativeLayout> 

       <!--MainView views --> 
       <RelativeLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content"> 
        <ExpandableListView 
         android:id="@+id/qwedit_main_elv" 
         android:layout_width="930dp" 
         android:layout_height="wrap_content" 
         android:indicatorLeft="? 
android:attr/expandableListPreferredItemIndicatorLeft" 
         android:divider="@color/colorPrimary" 
        android:dividerHeight="0.5dp" 
        android:layout_alignParentTop="true" 
        android:layout_alignParentEnd="true" 
        android:layout_marginTop="25dp"> 
       </ExpandableListView> 
      </RelativeLayout> 

     </RelativeLayout> 
    </FrameLayout> 
</LinearLayout> 

<!-- The navigation drawer that comes from the left --> 
<!-- Note that `android:layout_gravity` needs to be set to 'start' --> 
<android.support.design.widget.NavigationView 
    android:id="@+id/nvView" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:background="@android:color/white" 
    android:layout_marginTop="25dp" 
    app:menu="@menu/drawer_view" /> 
</android.support.v4.widget.DrawerLayout> 

这里是EVL的组布局:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="horizontal" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 
<TextView 
    android:id="@+id/qwedit_sidebar_elv_parent_title" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textColor="@color/black" 
    android:padding="3dp" 
    android:layout_marginLeft="40dp" 
    android:gravity="center" 
    android:textSize="20sp" 
    android:text="Category"/> 
<ImageView 
    android:id="@+id/qwedit_elv_parent_status" 
    android:layout_width="30dp" 
    android:layout_height="30dp" 
    android:layout_marginLeft="35dp" 
    android:src="@drawable/ic_warning"/> 
<TextView 
    android:id="@+id/qwedit_elv_parent_score" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="75dp" 
    android:layout_gravity="left" 
    android:gravity="right" 
    android:textColor="@color/colorPrimary" 
    android:textSize="20sp" 
    android:text="Score"/> 

</LinearLayout> 

和项目布局

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content"> 
<LinearLayout 
    android:id="@+id/qwedit_elv_item_score_container" 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 
    <LinearLayout 
     android:id="@+id/qwedit_main_badView" 
     android:layout_width="232.5dp" 
     android:layout_height="145.3dp" 
     android:background="@color/badScore"> 
     <TextView 
      android:id="@+id/qwedit_main_badTextView" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:gravity="center" 
      android:textColor="@color/white" 
      android:textSize="20sp" 
      android:text="Bad"/> 
    </LinearLayout> 
    <LinearLayout 
     android:id="@+id/qwedit_main_mediocreView" 
     android:layout_width="232.5dp" 
     android:layout_height="145.3dp" 
     android:background="@color/mediocreScore"> 
     <TextView 
      android:id="@+id/qwedit_main_mediumTextView" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:gravity="center" 
      android:textColor="@color/white" 
      android:textSize="20sp" 
      android:text="Mediocre"/> 
    </LinearLayout> 
    <LinearLayout 
     android:id="@+id/qwedit_main_goodView" 
     android:layout_width="232.5dp" 
     android:layout_height="145.3dp" 
     android:background="@color/goodScore"> 
     <TextView 
      android:id="@+id/qwedit_main_goodTextView" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:gravity="center" 
      android:textColor="@color/white" 
      android:textSize="20sp" 
      android:text="Good"/> 
    </LinearLayout> 
    <LinearLayout 
     android:id="@+id/qwedit_main_wcView" 
     android:layout_width="232.5dp" 
     android:layout_height="145.3dp" 
     android:background="@color/worldclassScore"> 
     <TextView 
      android:id="@+id/qwedit_main_worldclassTextView" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:gravity="center" 
      android:textColor="@color/white" 
      android:textSize="20sp" 
      android:text="World Class"/> 
    </LinearLayout> 
</LinearLayout> 
<EditText 
    android:layout_width="930dp" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/qwedit_elv_item_score_container" 
    android:focusable="true" 
    android:focusableInTouchMode="true" 
    android:hint="Comments"/> 

</RelativeLayout> 

我假定这是所有由于布局,但这里是我为它编写的CustomExpandableListAdapter,以防万一答案在于观点如何膨胀:

/** 
* Created by Tadhg on 9/8/2017. 
*/ 

public class QwEditMainCustomExpandableListAdapter extends BaseExpandableListAdapter { 
private Context context; 
private List<String> expandableListTitle; 
private HashMap<String, List<String>> expandableListDetail; 

//Values inits 
private int categoryScore; 
private int subCategoryScore; 
private boolean completedCategory; 
private boolean completedSubCategory; 

// ChildView views 
private View badScoreView; 
private View mediocreScoreView; 
private View goodScoreView; 
private View worldclassScoreView; 
TextView badScoreTextView; 
TextView mediocreScoreTextView; 
TextView goodScoreTextView; 
TextView worldClassScoreTextView; 
EditText questionCommentEditText; 

public QwEditMainCustomExpandableListAdapter(Context context, List<String> expandableListTitle, 
              HashMap<String, List<String>> expandableListDetail) { 
    this.context = context; 
    this.expandableListTitle = expandableListTitle; 
    this.expandableListDetail = expandableListDetail; 
} 

@Override 
public Object getChild(int listPosition, int expandedListPosition) { 
    return this.expandableListDetail 
      .get(this.expandableListTitle.get(listPosition)) 
      .get(expandedListPosition); 
} 

@Override 
public long getChildId(int listPosition, int expandedListPosition) { 
    return expandedListPosition; 
} 

@Override 
public View getChildView(int listPosition, final int expandedListPosition, boolean isLastChild, 
         View convertView, ViewGroup parent) { 
    final String expandedListText = (String) getChild(listPosition, expandedListPosition); 

    if(convertView == null) { 
     LayoutInflater layoutInflater = (LayoutInflater) this.context 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     convertView = layoutInflater.inflate(R.layout.qwedit_main_elv_item, null); 
    } 
    // ChildView views 
    badScoreView = convertView.findViewById(R.id.qwedit_main_badView); 
    mediocreScoreView = convertView.findViewById(R.id.qwedit_main_mediocreView); 
    goodScoreView = convertView.findViewById(R.id.qwedit_main_goodView); 
    worldclassScoreView = convertView.findViewById(R.id.qwedit_main_wcView); 
    badScoreTextView = (TextView) convertView.findViewById(R.id.qwedit_main_badTextView); 
    mediocreScoreTextView = (TextView) convertView.findViewById(R.id.qwedit_main_mediumTextView); 
    goodScoreTextView = (TextView) convertView.findViewById(R.id.qwedit_main_goodTextView); 
    worldClassScoreTextView = (TextView) convertView.findViewById(R.id.qwedit_main_worldclassTextView); 

    // TODO: TextView score subcategory setters 

    badScoreView.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      // TODO: add logic to change score 
      subCategoryScore = 1; 
      badScoreView.setBackgroundColor(Color.parseColor("#eca9a7")); 
      mediocreScoreView.setBackgroundColor(Color.parseColor("#f0ad4e")); 
      goodScoreView.setBackgroundColor(Color.parseColor("#5cb85c")); 
      worldclassScoreView.setBackgroundColor(Color.parseColor("#0275d8")); 
     } 
    }); 

    mediocreScoreView.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      // TODO: add logic to change score 
      subCategoryScore = 2; 
      badScoreView.setBackgroundColor(Color.parseColor("#d9534f")); 
      mediocreScoreView.setBackgroundColor(Color.parseColor("#f7d6a6")); 
      goodScoreView.setBackgroundColor(Color.parseColor("#5cb85c")); 
      worldclassScoreView.setBackgroundColor(Color.parseColor("#0275d8")); 
     } 
    }); 

    goodScoreView.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      // TODO: add logic to change score 
      subCategoryScore = 3; 
      badScoreView.setBackgroundColor(Color.parseColor("#d9534f")); 
      mediocreScoreView.setBackgroundColor(Color.parseColor("#f0ad4e")); 
      goodScoreView.setBackgroundColor(Color.parseColor("#addbad")); 
      worldclassScoreView.setBackgroundColor(Color.parseColor("#0275d8")); 
     } 
    }); 

    worldclassScoreView.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      // TODO: add logic to change score 
      subCategoryScore = 4; 
      badScoreView.setBackgroundColor(Color.parseColor("#d9534f")); 
      mediocreScoreView.setBackgroundColor(Color.parseColor("#f0ad4e")); 
      goodScoreView.setBackgroundColor(Color.parseColor("#5cb85c")); 
      worldclassScoreView.setBackgroundColor(Color.parseColor("#80baeb")); 
     } 
    }); 
    /** 
    * Use variables categoryScore and subCategoryScore to update scores 
    */ 
    return convertView; 
} 

@Override 
public int getChildrenCount(int listPosition) { 
    return this.expandableListDetail.get(this.expandableListTitle.get(listPosition)).size(); 
} 

@Override 
public Object getGroup(int listPosition) { 
    return this.expandableListTitle.get(listPosition); 
} 

@Override 
public int getGroupCount() { 
    return this.expandableListTitle.size(); 
} 

@Override 
public long getGroupId(int listPosition) { 
    return listPosition; 
} 

@Override 
public View getGroupView(int listPosition, boolean isExpanded, 
         View convertView, ViewGroup parent) { 
    String listTitle = (String) getGroup(listPosition); 
    if(convertView == null) { 
     LayoutInflater layoutInflater = (LayoutInflater) this.context 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     convertView = layoutInflater.inflate(R.layout.qwedit_main_elv_group, null); 
    } 

    TextView listTitleTextView = (TextView) convertView 
      .findViewById(R.id.qwedit_main_elv_parent_title); 

    listTitleTextView.setText(listTitle); 

    return convertView; 
} 

@Override 
public boolean hasStableIds() { return false; } 

@Override 
public boolean isChildSelectable(int listPosition, int expandedListPosition) { return true; } 
} 

任何积分或提示将是伟大的。我认为这可能是由于我的层次结构(或至少是它的一个子组织)中的视图数量所致,但我不确定,而且对于Android开发人员来说是相对较新的。

谢谢!

回答

0

我解决了这个问题,简单地加入android:windowSoftInputMode="adjustNothing|stateHidden"导致ActionBar不能扩展到996px当EditText获得焦点