今天踩了一个坑,坑是这样的,一个for循环,然后inflate一个布局,把这个布局动态的添加到一个linearlayout,布局代码如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
android:background="@color/white"
>
<android.support.v7.widget.AppCompatEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:maxLength="50"
android:layout_marginTop="8dip"
android:layout_marginBottom="8dip"
android:layout_marginLeft="16dip"
android:paddingLeft="6dip"
android:textColor="@color/app_main_black_text"
android:singleLine="true" />
<android.support.v7.widget.AppCompatRadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/vote_ver"
android:layout_marginRight="16dip"
android:visibility="visible"
android:gravity="center"
>
</android.support.v7.widget.AppCompatRadioButton>
<android.support.v7.widget.AppCompatCheckBox
android:layout_width="26dip"
android:layout_height="26dip"
android:layout_marginLeft="@dimen/vote_ver"
android:layout_marginRight="16dip"
android:visibility="gone" />
</LinearLayout>
里面有一个EditText,然后运行时候坑就出现了,无论怎么点击这个EditText,光标的显示一闪而过,软键盘也根本不会弹出来,为EditText添加了onFoucseChangeListener,根本不执行。。。然后我新建了一个DEMO,把这部分代码单独提取处来,写了个demo跑了一下,居然能正常运行,点击EditText也能弹出软键盘,,,,实在是又气又恼啊,不知道哪里出了问题,最后的解决方法是:
把EditText的 android:background="@drawable/et_search_ll_bg"这个属性去掉运行就好了,。点击EditText就能弹出软键盘,,你说这个问题奇不奇葩,都不知道这个问题怎么产生的。。上面的xml布局是能正常运行出来的布局界面