2016-05-16 3 views
3

Итак, в портретном режиме отображается правильно, независимо от того, находится ли timePicker в scrollView или нет.Analog timepicker внутри scrollView не отображает выбор времени

enter image description here

ландшафтный режим, когда находится внутри scroolView.

enter image description here

ландшафтный режим, когда нет scroolView.

enter image description here

[редактировать] Код:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.aapps.groupalarmclock.NewAlarmActivity"> 

<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:scaleType="centerCrop" 
    android:src="@drawable/background" 
    android:alpha="@dimen/background_transparency" 
    android:layout_centerHorizontal="true" /> 

<LinearLayout 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="@dimen/toolbar_height" 
    android:layout_alignParentTop="true" 
    android:weightSum="2" 
    android:background="@color/colorToolbar" 
    android:gravity="center_vertical" 
    android:id="@+id/linearLayout"> 

    <RelativeLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:id="@+id/rl_cancle" 
     android:layout_weight="1" 
     android:background="@drawable/click_effect" 
     android:gravity="center"> 

     <ImageView 
      android:layout_width="@dimen/toolbar_icon_size" 
      android:layout_height="@dimen/toolbar_icon_size" 
      android:id="@+id/iv_cancel" 
      android:src="@drawable/cancel" 
      android:layout_centerVertical="true" 
      android:layout_centerHorizontal="true" 
      android:layout_marginRight="@dimen/cancel_done_right_margin" 
      android:layout_marginEnd="@dimen/cancel_done_right_margin"/> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:textColor="@color/colorText" 
      android:id="@+id/tv_cancel" 
      android:layout_centerVertical="true" 
      android:layout_toRightOf="@+id/iv_cancel" 
      android:layout_toEndOf="@+id/iv_cancel" /> 

    </RelativeLayout> 

    <View 
     android:layout_width="1dp" 
     android:layout_height="@dimen/separator_height" 
     android:background="@color/colorLineSeparator" 
     android:id="@+id/v_cancel_done"> 
    </View> 

    <RelativeLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:id="@+id/rl_done" 
     android:layout_weight="1" 
     android:background="@drawable/click_effect" 
     android:gravity="center"> 

     <ImageView 
      android:layout_width="@dimen/toolbar_icon_size" 
      android:layout_height="@dimen/toolbar_icon_size" 
      android:id="@+id/iv_done" 
      android:src="@drawable/done" 
      android:layout_centerVertical="true" 
      android:layout_centerHorizontal="true" 
      android:layout_marginRight="@dimen/cancel_done_right_margin" 
      android:layout_marginEnd="@dimen/cancel_done_right_margin"/> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:textColor="@color/colorText" 
      android:id="@+id/tv_done" 
      android:layout_centerVertical="true" 
      android:layout_toRightOf="@+id/iv_done" 
      android:layout_toEndOf="@+id/iv_done" /> 

    </RelativeLayout> 

</LinearLayout> 


<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/scrollView" 
    android:layout_below="@+id/linearLayout" 
    android:layout_centerHorizontal="true" 
    android:fillViewport="true"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/lltp"> 


     <TimePicker tools:targetApi="23" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/timePicker" 
      android:timePickerMode="clock" 
      android:background="#80FFFFFF"/> 

    </RelativeLayout> 

</ScrollView> 

Кто-нибудь знает, что это не так?

ответ

2

В ScrollView есть свойство, чтобы прокручивать его содержимое, чтобы заполнить область просмотра или нет. По умолчанию он установлен в false и при открытии в альбомном режиме он не работает.

Так установить

android:fillViewport="true" 

внутри Scrollview и он должен работать.

Для получения дополнительной информации - http://developer.android.com/reference/android/widget/ScrollView.html

+0

все еще не работает. –

+0

Только что заметил это .... измените это в scroll-view 'android: layout_height =" match_parent "' – hashcode55

+0

Я пробовал, но ничего лучше. –

0

Я тот же вопрос, на устройстве с Android 5.1 (API 22), но android:fillViewport="true" не решить эту проблему в моем случае. Но если мы добавим дополнительный макет в качестве родителя для TimePicker, мы сможем решить эту проблему.

Следующий пример показывает фиксированное расположение:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fillViewport="true"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_weight="1" 
       android:minHeight="200dp" 
       android:orientation="horizontal"> 

       <TimePicker 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_gravity="center_horizontal" /> 
      </LinearLayout> 

      <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="right|bottom" 
       android:gravity="right|center_vertical" 
       android:onClick="onSave" 
       android:text="Save" /> 
     </LinearLayout> 
    </ScrollView> 
</LinearLayout> 

Обратите внимание, что TimePicker помещается внутри LinearLayout, который имеет параметр android:minHeight="200dp" и сам TimePicker имеет android:layout_width="match_parent" и android:layout_height="match_parent". Это помогает решить проблему в ориентации ladscape. minHeight параметр может иметь любое значение, которое вам нужно, но должно использоваться для рендеринга TimePicker.

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

  • Нет связанных вопросов^_^