【问题标题】:Listview inside edittext typting coverd by keyboard键盘覆盖的edittext类型中的Listview
【发布时间】:2012-10-03 13:31:25
【问题描述】:

列表视图内容有编辑文本和文本视图。在键入列表视图编辑文本的底部时动态加载列表视图内容,未显示填充的编辑文本。虚拟键盘覆盖编辑文本。

我也在活动中使用过这段代码:

getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

我在清单文件中使用了adjustpan、resize、statevisible,但没有任何改变。但它会在4.0以下完美运行。

customlist.xml 为

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"   android:layout_weight="1" 
    android:layout_height="match_parent" >

    <View
        android:id="@+id/view"
        android:layout_width="2dp"
        android:layout_height="fill_parent"
        android:layout_centerInParent="true"
        android:background="@android:color/transparent" />

    <EditText 
        android:id="@+id/textView21"
        android:layout_width="341dp"
        android:layout_height="60dp"
         android:layout_alignParentBottom="true"
        android:layout_weight="1" 
        android:layout_centerVertical="true"
        android:layout_marginRight="20dp"
        android:layout_toRightOf="@+id/view"
        android:background="@drawable/txt1"
        android:hint="Enter Value"
        android:layout_marginBottom="8dp"  
        android:layout_marginTop="8dp"  android:imeOptions="flagNoExtractUi"
        android:focusable="true" 
        android:paddingLeft="10dp" android:paddingRight="5dp"
        android:paddingTop="5dp"  android:singleLine="true"
        android:paddingBottom="5dp"
        android:textSize="25dp"
        android:textColor="@color/app_text_color"
         />

    <TextView
        android:id="@+id/textView1" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:layout_marginRight="20dp"
        android:layout_toLeftOf="@+id/view"
        android:paddingBottom="5dp"
        android:paddingLeft="10dp"
        android:paddingTop="5dp"   android:textSize="25dp"
        android:text="Large ryw4rtb "
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="@color/app_text_color"
       />

</RelativeLayout>

和 main.xml 一样

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:layout_marginBottom="5dp" android:id="@+id/sceen"
    android:background="@drawable/full_bg"
    android:orientation="vertical" >

    <include
        android:id="@+id/titleLayout"
        layout="@layout/title" />

    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal" >

        <LinearLayout
            android:id="@+id/left"
            android:layout_width="326dp"
            android:layout_height="fill_parent"
            android:background="@drawable/left_bg" >

            <ListView 
                android:id="@+id/list"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:layout_marginTop="20dp"
                android:background="@drawable/left_table_bg"
                android:cacheColorHint="#00000000"
                android:transcriptMode="alwaysScroll"
                android:layout_weight="1"
                android:divider="@drawable/left_table_line"
                android:paddingLeft="5dp"
                android:paddingRight="5dp" >
            </ListView>
        </LinearLayout>

        <RelativeLayout
            android:id="@+id/lay_healthy"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_marginBottom="5dp"
            android:background="@drawable/right_side_bg" >
 <RelativeLayout
            android:id="@+id/lay_healthy1"   android:layout_above="@+id/btn"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
             >

            <ListView
                android:id="@+id/listView1"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"

                android:layout_weight="1" 
                android:layout_alignParentTop="true"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_marginTop="10dp"
                android:background="@drawable/available_right_bg"
                android:cacheColorHint="#00000000"
                android:padding="20dp" />

             <ListView
                android:id="@+id/listView2"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"

                android:layout_alignParentTop="true"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_marginTop="10dp"
                android:background="@drawable/available_right_bg"
                android:cacheColorHint="#00000000"
                android:padding="20dp"
                android:visibility="gone" />

             <ListView
                android:id="@+id/listView3"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"

                android:layout_alignParentTop="true"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_marginTop="10dp"
                android:background="@drawable/available_right_bg"
                android:cacheColorHint="#00000000"
                android:padding="20dp"
                android:visibility="gone" />
           </RelativeLayout> 



        <RelativeLayout
                android:id="@+id/btn" 
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_above="@+id/btn1" 
                android:layout_alignParentBottom="true"
                android:layout_marginBottom="20dp"
                android:layout_marginTop="10dp" >

                <Button 
                    android:id="@+id/button1"
                    android:layout_width="200dp"
                    android:layout_height="57dp"
                    android:layout_alignParentLeft="true"
                    android:layout_marginBottom="10dp"
                    android:layout_marginLeft="160dp"
                    android:background="@drawable/bt_submit" />

                <Button
                    android:id="@+id/button2"
                    android:layout_width="200dp"
                    android:layout_height="57dp"
                    android:layout_alignParentRight="true"
                    android:layout_marginBottom="10dp"
                    android:layout_marginRight="160dp"
                    android:background="@drawable/bt_reset" />
            </RelativeLayout>

            <RelativeLayout
                android:id="@+id/btn1"
                android:layout_width="fill_parent"
                android:layout_height="20dp"
                android:layout_alignParentBottom="true" >
            </RelativeLayout>
              </RelativeLayout>
    </LinearLayout>

</LinearLayout>

请帮我解决这个问题。

【问题讨论】:

标签: android android-layout


【解决方案1】:

除了你填写的EditText,你肯定还有其他的视图,比如Header或者Button等等,

所以,

跟踪软键盘是否打开,使这些视图不可见,并在软键盘关闭/隐藏时使其可见

没有直接的方法来跟踪显示/隐藏的软键盘,因此使用我在我的应用程序中使用的这段代码:

//your_button is the layout of your button view or a header view. if its just a view cast it to

//appropriate Class
final LinearLayout your_button = (LinearLayout) findViewById(R.id.your_button);
//activityRootView is the Layout you are using for the Activity
final View activityRootView = findViewById(R.id.layout_parent);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
            @Override
public void onGlobalLayout() {
    int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
    if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...

    your_button.setVisibility(Visibility.GONE);
    }else{

    your_button.setVisibility(Visibility.VISIBLE);
        }
    }
});

【讨论】:

  • 我需要显示编辑文本,当我打字时。但它会变得不可见。
【解决方案2】:

尝试在声明活动的清单中添加它。

     <activity android:name=".YourActivity"
     android:windowSoftInputMode="stateHidden"/>

【讨论】:

  • 谢谢,但布局没有任何变化,当我在底部输入编辑文本时,编辑文本不可见。
  • 用“adjustResize”替换“stateHidden”
  • 我尝试使用 android:windowSoftInputMode="stateVisible|adjustResize|adjustPan" 但没有任何改变。
  • LayoutParams.FLAG_LAYOUT_NO_LIMITS ,允许窗口扩展到屏幕之外。
  • android:windowSoftInputMode="stateVisible|adjustResize|adjustPan" 它适用于 2.2 而不是 3.0 及更高版本。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多