2015-05-29 7 views
0

У меня есть относительный макет. Внутри которой у меня есть много просмотров, таких как редактирование текста, текстовых просмотров и т. Д. В этом я много анимации. Все было прекрасно. Но в какой-то момент у меня есть требование.вид скользящий над макетом

Это страница с паролем. Создайте и подтвердите пароль. Два edittexts один за другим. Если пароль не соответствует этому требованию, простое оранжевое изображение должно соскользнуть с сообщением об ошибке «Invalid password».

Поэтому я поместил пароль для создания и подтверждения в линейной компоновке. Линейный макет будет скользить вверх, позволяя вводить пароли пользователя. После проверки, если есть ошибка, линейный макет должен скользить вниз, а простой вид будет скользить вверх. Я сохранил представление невидимым, и, когда это необходимо, я сделал его видимым и написал код для продвижения вверх. Тот же код работает, когда я просто использую один текст редактирования вместо линейного макета. Но при использовании линейного макета он не работает. Я делаю что-то неправильно?

Добавление кода к нему. Код, относящийся к этой проблеме, начинается до конца кодирования.

Я объявила линейную компоновку как просмотр, а НЕ VIEWGROUP.

EDIT: После анализа я обнаружил, что вид, который я пытаюсь сдвинуть вверх после сползания макета, скрыт где-то в иерархии представлений.

view.bringToFront() помогает принести представление об ошибке на передний план и скользить вверх.

Но после этого проблема заключается в том, что после того, как моя линейная компоновка сдвинется вниз, представление об ошибке сразу не сдвинется с места. Поскольку я использую метод bringToFront(), он отображает представление сначала на весь экран (с цветом фона как оранжевый), а затем начинается спуск.

Я не уверен, правильно ли это, но я исправил эту проблему следующим образом.

  1. нет цвета фона был уделен мнение
  2. Я использовал errorView.bringToFront() и errorView.setVisibility (истина) в animationEnd() в виде анимации слушателя Layout slidingdown.
  3. Я определил скользящую анимацию для errorView в той же анимацииEnd() макета, спускающего вниз слушателя
  4. В анимационном прослушивании animationStart(), который я просматривал, я определил цвет фона errorView. Теперь он работает как ожидалось.

Но дайте мне знать, как лучше это сделать.

// Декларация

Просмотр greyView, orangeView, yellowView, Blueview, orangeErrorView, letsGetStartedView, welcomeBckView, passwordMasterLayout, orangePwdErrorView; TextView welcomeText, errorTextView, allowGetStartedTextView, welcomeBckTxtView, errorPwdMsg;

// Пароль Обработка ошибок

orangePwdErrorView = v.findViewById(R.id.orangePasswordErrorView); 
    errorPwdMsg = (TextView) v.findViewById(R.id.errorPasswordMessage); 

// Разметка код

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/sample_main_layout"> 

    <FrameLayout 
     android:id="@+id/sample_content_fragment" 
     android:layout_weight="76.4" 
     android:layout_width="match_parent" 
     android:layout_height="0px" /> 

    <FrameLayout 
     android:id="@+id/bottomPanel" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="23.6"> 
    </FrameLayout> 
</LinearLayout> 

sample_content_fragment framelayout принимает код ниже

<RelativeLayout 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 

    <View 
     android:id="@+id/grey" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#58595B" /> 

    <View 
     android:id="@+id/orange" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#F26724" 
     android:visibility="invisible" /> 



    <View 
     android:id="@+id/yellow" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#FDB518" 
     android:visibility="invisible" /> 

    <View 
     android:id="@+id/blue" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#1893D2" 
     android:visibility="invisible" /> 






    <TextView 
     android:layout_width="260dp" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:text="@string/welcome" 
     android:id="@+id/welcomeTextView" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="51dp" 
     android:textColor="#ffffff" 
     android:textSize="20dp" 
     android:textStyle="bold" 
     android:visibility="invisible" 
     /> 

    <ImageView 
     android:layout_height="60dp" 
     android:layout_width="60dp" 
     android:id="@+id/clinicloud_logo" 
     android:clickable="true" 
     android:src="@drawable/clinicloud_icon" 
     android:layout_marginRight="50dp" 
     android:layout_alignParentStart="true" 
     android:layout_marginStart="35dp" 
     android:layout_alignParentBottom="true" 
     android:layout_marginBottom="40dp" /> 

    <View 
     android:id="@+id/orangeErrorView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#F26724" 
     android:visibility="invisible" /> 





    <EditText 
     android:layout_width="match_parent" 
     android:layout_height="90dp" 
     android:inputType="textEmailAddress" 
     android:ems="10" 
     android:id="@+id/emailEditText" 
     android:text="@string/enter_email" 
     android:layout_gravity="center" 
     android:background="#f4f4f4" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentStart="true" 
     android:visibility="invisible"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:id="@+id/errorMessage" 
     android:layout_alignTop="@+id/welcomeTextView" 
     android:layout_centerHorizontal="true" 
     android:textColor="#ffffff" 
     android:visibility="invisible"/> 

    <!--UI components for welcome back page--> 

    <View 
     android:id="@+id/welcomeBackView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#134F9F" 
     android:visibility="invisible" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/welcome_back" 
     android:id="@+id/welcomeBackTxtView" 
     android:textColor="#ffffff" 
     android:layout_alignTop="@+id/welcomeTextView" 
     android:layout_alignStart="@+id/clinicloud_logo" 
     android:textSize="20dp" 
     android:textStyle="bold" 
     android:visibility="invisible"/> 

    <EditText 
     android:layout_width="wrap_content" 
     android:layout_height="90dp" 
     android:ems="10" 
     android:id="@+id/password" 
     android:layout_alignTop="@+id/emailEditText" 
     android:layout_alignParentStart="true" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentEnd="true" 
     android:text="Password" 
     android:visibility="invisible" 
     android:background="#d2d1d1" 
     /> 


    <!--UI components for Let's get started page--> 
    <View 
     android:id="@+id/letsGetStartedView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#5C3A91" 
     android:visibility="invisible" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Let&apos;s get started" 
     android:id="@+id/letsGetStartedTxtView" 
     android:textColor="#ffffff" 
     android:layout_alignTop="@+id/welcomeTextView" 
     android:layout_alignStart="@+id/clinicloud_logo" 
     android:textSize="20dp" 
     android:textStyle="bold" 
     android:visibility="invisible"/> 

    <!--Linear layout to show the create and confirm password--> 

    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="180dp" 
     android:gravity="bottom" 
     android:layout_alignBottom="@+id/emailEditText" 
     android:layout_alignParentStart="true" 
     android:weightSum="1" 
     android:id="@+id/passwordMasterView" 
     android:visibility="invisible"> 

     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:inputType="text" 
      android:id="@+id/createPwd" 
      android:layout_weight="0.50" 
      android:background="#F4F4F4" 
      android:text="@string/create_password" 
      /> 

     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:inputType="text" 
      android:id="@+id/confirmPwd" 
      android:layout_weight="0.50" 
      android:background="#E3E3E3" 
      android:text="@string/confirm_password" /> 
    </LinearLayout> 

    <!-- To show password errors--> 

    <LinearLayout 
     android:id="@+id/orangePasswordErrorView" 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#F26724" 
     android:visibility="invisible" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:id="@+id/errorPasswordMessage" 
     android:layout_alignTop="@+id/welcomeTextView" 
     android:layout_centerHorizontal="true" 
     android:textColor="#ffffff" 
     android:visibility="invisible" 
     /> 

    <!-- To show password errors--> 

</RelativeLayout> 

Логика Ява в https://stackoverflow.com/questions/30523599/sliding-up-and-down-android

Пожалуйста, направьте на неправильные коды

+0

Можете ли вы разместить код? –

ответ

0

Я сохранил вид невидимым, и, когда требуется, я сделал его видимым и написал код для перехода вверх.

Я думаю, что вы должны сделать это в DialogFragment или обычая AlertDialog, что будет показано выше макете, если не хотите, чтобы сделать это попробовать обволакивают ваше RelativeLayout в FrameLayout и добавляя в него LinearLayout, например, но visout код трудно скажите, в чем проблема:

0

Вы должны рассмотреть возможность использования библиотеки для скользящей панели, для которой у меня был отличный опыт работы (и поддержка функций, которые вы используете) - это AndroidSlidingUpPanel от umano. https://github.com/umano/AndroidSlidingUpPanel

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