2016-02-16 2 views
2

Я пытаюсь сделать мой EditText занять оставшееся пустое пространство экрана между панелью инструментов сверху и широкой кнопкой отправки внизу.TextInputLayout Счетчик EditText запускает экран в LinearLayout

Однако, когда я использую 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> 

Вот как это выглядит сейчас:

enter image description here

Вот что я хочу, чтобы выглядеть (с 0/300 счетчика на нижней правой):

enter image description here

+0

Не могли бы вы загрузить скриншот или изображение, что хотите? – Kae10

+0

@ Kae10 Готово. См. Счетчик внизу справа? – Micro

ответ

1

Попробуйте обновленный 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> 

Выход:

enter image description here

Я надеюсь, что его помогает.

+0

Итак, текстовый текст 'tvCounter' мне нужно будет обновить код Java? – Micro

+0

Да. Вам необходимо изменить согласно вашему требованию. – pRaNaY

+0

Я вижу. Я надеялся не делать этого, чтобы счетчик просто автоматически обновлял количество символов =) – Micro

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" для кнопки отправки.

Надеюсь, что это поможет;)

Смежные вопросы