Android 如何设置高度和高度;Edittext的宽度,这样当我在Edittext中键入按钮旁边的内容时,应该可以看到

Android 如何设置高度和高度;Edittext的宽度,这样当我在Edittext中键入按钮旁边的内容时,应该可以看到,android,android-layout,android-ui,Android,Android Layout,Android Ui,我在LinearLayout中有EditText和按钮。我现在已使按钮不可见&我的编辑文本是填充父项 但是,当我想在EditText中输入内容时,编辑文本的宽度应环绕&按钮旁边应可见。任何代码片段都会非常有用。按钮具有setVisibility方法。要使其可见,请使用以下命令: Button button.setVisibility(View.VISIBLE); 不要将EditText设置为fill\u parent。您可以尝试使用: <EditText android:layo

我在
LinearLayout
中有
EditText
按钮
。我现在已使
按钮
不可见&我的
编辑文本
填充父项


但是,当我想在
EditText
中输入内容时,编辑文本的宽度应环绕&
按钮
旁边应可见。任何代码片段都会非常有用。

按钮具有setVisibility方法。要使其可见,请使用以下命令:

Button button.setVisibility(View.VISIBLE);

不要将
EditText
设置为
fill\u parent
。您可以尝试使用:

<EditText
    android:layout_width = "0dp"
    android:layout_height = "wrap_content"
    android:layout_weight = "1"
    />

<YourButton/>

我假设您的
线性布局
是水平的。

试试这个

<LinearLayout android:orientation="horizontal">
     <EditText android:layout_weight="1" android:layout_height="wrap_content" 
         anroid:layout_width="0dp" />
     <Button android:layout_width="50dp" android:layout_height="wrap_content"
         android:visibility="gone" />
</LinearLayout>

我假设您已经拥有在EditText中键入内容时显示按钮的代码,请尝试以下操作:

  • 注册到您的编辑文本
  • 如果hasFocus==true,则重写并执行以下操作:
    • 将EditText的LayoutParameters更改为宽度和高度均为wrap_内容
    • 将按钮设置为可访问
试试这个:

布局:

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

    <EditText
        android:id="@+id/editText"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

    <Button
        android:id="@+id/btnClickMe"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Click Me"
        android:visibility="gone" />
</LinearLayout>

您认为当我输入内容时,edittext会自动换行并显示按钮吗
EditText editText=(EditText)findViewById(R.id.editText);
    final Button btnClickMe=(Button) findViewById(R.id.btnClickMe);

    editText.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) {
            btnClickMe.setVisibility(View.VISIBLE);
        }
    });