Android TextInputLayout编辑文本计数器在LinearLayout中脱离屏幕运行
我试图让我的Android TextInputLayout编辑文本计数器在LinearLayout中脱离屏幕运行,android,Android,我试图让我的EditText占据屏幕顶部工具栏和底部宽提交按钮之间剩余的空白 但是,当我使用match\u parent处理该EditText时,计数器会从屏幕上消失(最后出现在按钮后面)。我似乎不知道该如何表现出来 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http:
EditText
占据屏幕顶部工具栏和底部宽提交按钮之间剩余的空白
但是,当我使用match\u parent
处理该EditText
时,计数器会从屏幕上消失(最后出现在按钮后面)。我似乎不知道该如何表现出来
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.myapp.app.PostActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:overScrollMode="never"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:id="@+id/textLinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
>
<android.support.design.widget.TextInputLayout
android:id="@+id/textContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
app:counterEnabled="true"
app:counterMaxLength="300">
<EditText
android:id="@+id/EditText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00000000"
android:gravity="top|left"
android:inputType="textMultiLine|textCapSentences"
android:maxLength="300"
android:scrollbars="vertical"/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/submitArea"
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="horizontal">
<Button
android:id="@+id/postButton"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Submit" />
</LinearLayout
</LinearLayout>
下面是我想要它的样子(右下角有0/300
计数器):
请尝试以下针对您的布局更新的xml代码:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".AppTourActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:overScrollMode="never"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:id="@+id/textLinearLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin">
<android.support.design.widget.TextInputLayout
android:id="@+id/textContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
app:counterEnabled="true"
app:counterMaxLength="300">
<EditText
android:id="@+id/EditText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00000000"
android:gravity="top|left"
android:inputType="textMultiLine|textCapSentences"
android:maxLength="300"
android:scrollbars="vertical" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<TextView
android:id="@+id/tvCounter"
tools:text="0/300"
android:layout_alignParentBottom="true"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10sp"
android:layout_height="wrap_content" />
</RelativeLayout>
<LinearLayout
android:id="@+id/submitArea"
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="horizontal">
<Button
android:id="@+id/postButton"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Submit" />
</LinearLayout>
</LinearLayout>
我希望它能对您有所帮助。试着改用RelativeLayout,认为问题在于您的布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.myapp.app.PostActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:overScrollMode="never"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:id="@+id/textLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/appBarLayout"
android:layout_above="@id/submitArea"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
>
<android.support.design.widget.TextInputLayout
android:id="@+id/textContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
app:counterEnabled="true"
app:counterMaxLength="300">
<EditText
android:id="@+id/EditText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00000000"
android:gravity="top|left"
android:inputType="textMultiLine|textCapSentences"
android:maxLength="300"
android:scrollbars="vertical"/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/submitArea"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<Button
android:id="@+id/postButton"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Submit" />
</LinearLayout>
</RelativeLayout>
技巧是使用下面的android:layout\u
和上面的android:layout\u
作为中间布局,使用android:layout\u alignParentBottom=“true”
作为提交按钮
希望这有帮助;) 你能上传你想要的截图或图片吗?@Kae10 Done。看到右下角的计数器了吗?那么tvCounter
TextView我就必须用Java代码更新自己了?是的。我明白了,你需要根据你的要求改变。我希望不必这样做,计数器只会自动更新字符计数=)