2016-03-20 4 views
1

Я пытаюсь реализовать элементы управления для своего музыкального проигрывателя.Android View не становится VISIBLE

Вот мой XML:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/white" 
    android:clickable="true" 
    android:fitsSystemWindows="true" 
    app:behavior_hideable="true" 
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior"> 

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

     ... 

      <LinearLayout 
       android:id="@+id/control_toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true" 
       android:gravity="bottom" 
       android:orientation="horizontal" 
       android:weightSum="4"> 

<!-- This is volume control Button --> 
       <RelativeLayout 
        android:id="@+id/bottom_sheet_control_volume_container" 
        android:layout_width="wrap_content" 
        android:layout_height="56dp" 
        android:layout_weight="1" 
        android:gravity="center"> 

        <ImageButton 
         android:id="@+id/bottom_sheet_control_volume" 
         android:layout_width="48dp" 
         android:layout_height="48dp" 
         android:background="@drawable/item_bg_transparent" 
         android:src="@drawable/ic_volume_up_black_24dp" /> 
       </RelativeLayout> 

<!-- Other Buttons --> 
       ... 
      </LinearLayout> 

<!-- Layout with volume control SeekBar --> 
      <io.codetail.widget.RevealFrameLayout 
       android:id="@+id/reveal_seek_bar_volume" 
       android:layout_width="match_parent" 
       android:layout_height="56dp" 
       android:layout_alignParentBottom="true" 
       android:focusable="true" 
       android:focusableInTouchMode="true" 
       android:visibility="visible"> 

       <LinearLayout 
        android:id="@+id/container_seek_bar_volume" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:background="@color/white" 
        android:focusable="true" 
        android:focusableInTouchMode="true" 
        android:gravity="center_vertical" 
        android:orientation="horizontal" 
        android:visibility="gone"> 

        <ImageButton 
         android:id="@+id/container_seek_bar_volume_close" 
         android:layout_width="40dp" 
         android:layout_height="40dp" 
         android:layout_marginLeft="16dp" 
         android:layout_marginStart="16dp" 
         android:background="@drawable/item_bg_transparent" 
         android:src="@drawable/ic_close_black_24dp" /> 

        <android.support.v7.widget.AppCompatSeekBar 
         android:id="@+id/seek_bar_volume" 
         android:layout_width="match_parent" 
         android:layout_height="30dp" 
         android:layout_margin="16dp" 
         android:max="100" 
         android:paddingLeft="8dp" 
         android:paddingRight="8dp" 
         android:paddingTop="0dp" 
         android:progress="100" 
         app:theme="@style/AppTheme.SeekBar.Accent" /> 
       </LinearLayout> 
      </io.codetail.widget.RevealFrameLayout> 

     </RelativeLayout> 
    </LinearLayout> 
</FrameLayout> 

И мой код:

LLcontainerSBvolume = (LinearLayout) findViewById(R.id.container_seek_bar_volume); 
IBcontrolVolume = (ImageButton) findViewById(R.id.bottom_sheet_control_volume); 
     IBcontrolVolume.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       LLcontainerSBvolume.setVisibility(View.VISIBLE); 
      } 
     }); 

Я также попытался запросить фокус для ImageButton и других Views:

IBcontrolVolume.requestFocus(); 
LLcontainerSBvolume.requestFocus(); 
LLcontainerSBvolume.requestLayout(); 

ПРОБЛЕМА

Проблема заключается в следующем:

Когда я начинаю Activity, нажмите на песню, откройте BottomSheet и нажмите регулятор громкости ImageButton, Seekbar не становится VISIBLE. Я должен нажать на другой View, а затем объем ImageButton также работает.

+0

Почему вы делаете всего 'container_seek_bar_volume' вида GONE, вместо применения его только 'seek_bar_volume' –

+0

@ShreeKrishna, да, потому что рядом с' ImageButton' рядом с 'SeekBar' –

+0

вы хотите, чтобы оба они были невидимыми при первом запуске и делали видимыми прагматически. Тогда оба стали видимыми или только один стал видимым? –

ответ

2

Макет, который вы устанавливаете Visibility в GONE при запуске и делает его видимым во время выполнения, не является официальным андроидом Layout. Его внутренняя пользовательская библиотека io.codetail.widget.RevealFrameLayout, которая может иметь ошибки при изменении Visibility во время выполнения. Поэтому не используйте android:visibility в контейнере ImageButton и AppCompatSeekBar. Сделайте это отдельно, как

<ImageButton 
    ----- 
android:visibility="gone" /> 


<android.support.v7.widget.AppCompatSeekBar 
    ----- 
android:visibility="gone" /> 

Тогда внутри onClick сделать как видимый или один видимый как ваши требования, как здесь

@Override 
public void onClick(View v) { 
    myImageButton.setVisibility(View.VISIBLE); 
    myAppCompatSeekBar.setVisibility(View.VISIBLE); 
} 
Смежные вопросы