4

问题:在可以处理我的两个窗格Fragment容器的设备上,两个窗格显示一个列表视图和选定的视图并排显示,EditView android:hint在输入文本时隐藏。但是,在摩托罗拉 XOOM 和 Nexus 7 上,android:hint插入文本时不会消失.

更新:我已经弄清楚了ListView调整大小活动的问题。由于重绘,它只显示ListView没有调整大小。但是,我EditText不隐藏的问题android:hint仍然存在。我现在添加了我的问题的更新图像以及下面的更新代码。除非其他人认为它适合删除,否则我将保留旧的东西以作记录。:

更新照片

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/contact_detail_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

        <ImageButton
            android:id="@+id/chat_camera_button"
            style="android:selectableItemBackground"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:background="?android:attr/selectableItemBackground"
            android:src="@drawable/camera_button" />

        <ImageButton
            android:id="@+id/chat_text_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_toLeftOf="@+id/chat_record_button"
            android:background="?android:attr/selectableItemBackground"
            android:src="@drawable/send_text_button" />

        <ImageButton
            android:id="@+id/chat_record_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:background="@android:color/transparent"
            android:focusableInTouchMode="true"
            android:longClickable="true"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:src="@drawable/mic_disabled" />

       <EditText
           android:id="@+id/chat_message_text"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_alignParentBottom="true"
           android:layout_toLeftOf="@+id/chat_text_button"
           android:layout_toRightOf="@+id/chat_camera_button"
           android:ems="10"
           android:hint="@string/message_hint"
           android:inputType="textMultiLine|textCapSentences"
           android:maxLines="3"
           android:minLines="1" />

        <ListView
            android:id="@+id/messages_list"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/chat_message_text"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:stackFromBottom="true"
            android:transcriptMode="alwaysScroll" />

</RelativeLayout>

更新 [旧]:这似乎只适用于我在家测试的 Droid RAZR。我已经测试过 3. 其他人在 Droid RAZR 上有问题吗?

我试图让我的列表视图和编辑文本在用户输入更多行(最多 3 行)时重新调整大小。但是,由于某种原因,提示并没有消失,列表视图也没有重新调整大小。

此外,当文本在里面时,我的 Edit-text 中使用的 android:hint 不会消失。

这是错误图像的示例(忽略发送按钮,我不再重新调整大小)

想要的人的图像:http: //i.stack.imgur.com/e7FJJ.png

Black - ListView

White - EditText + Button

Green - Text inside EditText

以下是我的 XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/contact_detail_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

        <Button
            android:id="@+id/details_record_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:text="Send" />

       <EditText
           android:id="@+id/chat_message_input"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_alignParentBottom="true"
           android:layout_alignParentLeft="true"
           android:layout_toLeftOf="@+id/details_record_button"
           android:ems="10"
           android:hint="@string/message_hint"
           android:paddingRight="10dp"
           android:paddingTop="10dp"
           android:inputType="textMultiLine"
           android:minLines="1"
           android:maxLines="3"
           android:textColor="#00FF00"/>

        <ListView
            android:id="@+id/messages_list"
            android:layout_width="match_parent"
            android:layout_height="fill_parent"
            android:layout_above="@+id/chat_message_input"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:background="#000000" />

</RelativeLayout>
4

3 回答 3

4

就我而言,发生这种情况是因为我膨胀了相同布局的多个层。例如,我在我的活动中这样做onCreate

setContentView(R.layout.activity_login);

同时也在我的片段中这样做:

View view = inflater.inflate(R.layout.activity_login, container, false);
...
return view;

这将创建 2 个完全重叠的控件。因此,当您在控件中键入文本时EditText,您只需将其键入到其中一个控件中。因此,其中一个显示您键入的文本,而另一个为空且未聚焦的文本正确显示了提示。

因此,解决方案是从活动或所有片段中删除布局。

于 2014-11-19T16:00:23.200 回答
1

将 TextWatcher 添加到您的 editText 中,然后当您看到文本不等于“”时,将提示文本设置为“”

et1.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

            // TODO Auto-generated method stub
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            // TODO Auto-generated method stub
        }

        @Override
        public void afterTextChanged(Editable s) {

            // MAKE CHANGES TO YOUR EDITTEXT HINT TEXT HERE
        }
    });
于 2013-01-03T21:38:20.480 回答
0

只是安装 APK 和启动应用程序的多次迭代会导致此问题。卸载模拟器或设备中的APP,应该可以解决问题。

您可以尝试按下后退按钮并重新启动应用程序,以确保您没有多个片段实例。

于 2017-02-24T19:26:15.370 回答