我正在尝试让我的EditText
占据屏幕顶部工具栏和底部宽提交按钮之间剩余的空白区域。
然而,当我对match_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
计数器):
答案 0 :(得分:1)
尝试以下更新的布局xml代码:
#include <stdio.h>
#include <stdlib.h>
void main()
{
int testNums[] = {3, 0x12, 0xFF, -3};
int testBits[] = {9, 7, 12, 15};
int i;
for (i = 0; i < sizeof(testNums) / sizeof(testNums[0]); i++)
printBin(testNums[i], testBits[i]);
}
void printBin(int num, int bits)
{
int pow;
int mask = 1 << bits - 1;
for(pow=0; pow<bits; pow++)
{
if(mask & num)
printf("1");
else
printf("0");
num<<1;
}
printf("\n");
}
<强>输出:强>
我希望它会帮助你。
答案 1 :(得分:1)
尝试使用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_below
和android:layout_above
作为中间布局,android:layout_alignParentBottom="true"
作为提交按钮。
希望这会有所帮助;)