2015-06-24 3 views
-1

Мне нужно отключить просмотр программно, поэтому я использовал setVisibility (view.GONE) в действии. У моего xml есть две кнопки: нижняя и верхняя и две относительные макеты с именем lower_lay и upper_lay. Когда я нажимаю нижнюю кнопку, мне нужно включить lower_lay, и я нажимаю верхнюю кнопку, чтобы включить upper_lay. И в upeer_lay, и в lower_lay, имеющие изображения и выполняющие onTouch событие. Теперь моя проблема, когда я нахожусь в lower_lay, изображения upper_lay отключены, но когда я касаюсь пустого места в lower_lay, появляются изображения верхнего уровня ... и в upper_lay у меня возникает эта проблема. Почему взгляд не закончился?setVisibility (view.GONE) не работает Android

Я пробую это от 3 дней .... пожалуйста, любой помогите мне.

XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/r1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#ffffff" 

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

     android:fillViewport="true"> 

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

     <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#1e356a"> 

     <TextView 
      android:id="@+id/placce_head" 
      android:layout_width="wrap_content" 
      android:layout_height="25dp" 
      android:layout_centerHorizontal="true" 
      android:layout_centerVertical="true" 
      android:layout_marginTop="10dp" 
      android:layout_marginBottom="10dp" 
      android:text="Hyderabad to banglore" 
      android:textColor="#ffffff" 
      android:textSize="20dp" /> 



    </RelativeLayout> 
      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="#78869c" 
       android:weightSum="2" 

       android:orientation="horizontal"> 


      <TextView 
       android:id="@+id/seats" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:layout_centerHorizontal="true" 
       android:layout_centerVertical="true" 
       android:layout_marginLeft="10dp" 
       android:text="Selected Seats" 
       android:textColor="#ffffff" 
       android:textSize="16dp" /> 
       <TextView 
        android:id="@+id/totalamount" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:layout_centerHorizontal="true" 
        android:layout_centerVertical="true" 
        android:layout_marginLeft="10dp" 
        android:text="Total Amount" 
        android:textColor="#ffffff" 
        android:textSize="16dp" /> 
      </LinearLayout> 
      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="#78869c" 
       android:weightSum="2" 
       android:orientation="horizontal"> 


       <TextView 
        android:id="@+id/seat_num" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:layout_centerHorizontal="true" 
        android:layout_centerVertical="true" 
        android:layout_marginLeft="10dp" 

        android:textColor="#ffffff" 
        android:textSize="16dp" /> 
       <TextView 
        android:id="@+id/total_amount" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:layout_marginLeft="10dp" 
        android:layout_centerHorizontal="true" 
        android:layout_centerVertical="true" 


        android:textColor="#ffffff" 
        android:textSize="16dp" /> 
     </LinearLayout> 
      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="vertical" 
       android:background="#1e356a" 
       > 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="#1e356a" 
       android:layout_marginTop="5dp" 
       android:layout_marginBottom="10dp" 
       android:orientation="horizontal"> 
       <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="6dp" 
        android:src="@drawable/bluesmall"/> 
       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="6dp" 
        android:text="Available" 
        android:textSize="12dp" 
        android:textColor="#ffffff"/> 
       <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="5dp" 
        android:src="@drawable/greensmall"/> 
       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="6dp" 
        android:textSize="12dp" 
        android:textColor="#ffffff" 
        android:text="Selected"/> 
       <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="6dp" 

        android:src="@drawable/pinksmall"/> 
       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Ladies" 
        android:textSize="12dp" 
        android:textColor="#ffffff" 
        android:layout_marginLeft="6dp"/> 
       <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
        android:layout_marginLeft="6dp" 
       android:src="@drawable/redsmall"/> 
       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="6dp" 
        android:textSize="12dp" 
        android:textColor="#ffffff" 
        android:text="Booked"/> 


       </LinearLayout> 
       <LinearLayout 
        android:id="@+id/sleeper_lay" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:orientation="horizontal" 
        android:background="#78869c" 
        android:weightSum="2" 

        android:padding="7dp" 
        android:layout_marginTop="10dp" 
        android:layout_marginLeft="10dp" 
        android:layout_marginRight="10dp" 
        > 
        <Button 
         android:id="@+id/lower" 
         android:layout_width="0dp" 
         android:layout_weight="1" 
         android:text="Lower" 
         android:textColor="#F93249" 
         android:gravity="center" 
         android:textSize="18dp" 
         android:layout_height="wrap_content" /> 
        <Button 
         android:id="@+id/upper" 
         android:layout_width="0dp" 
         android:layout_weight="1" 
         android:text="Upper" 
         android:textSize="18dp" 
         android:textColor="#ffffff" 
         android:gravity="center" 
         android:layout_height="wrap_content" /> 

       </LinearLayout> 





      <RelativeLayout 
     android:id="@+id/relative_layout" 
       android:layout_marginLeft="10dp" 
       android:layout_marginRight="10dp" 
       android:layout_marginBottom="10dp" 
       android:background="@drawable/bg_border" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:gravity="center" > 






    </RelativeLayout> 
       <RelativeLayout 
        android:id="@+id/relative_layout_two" 

        android:layout_marginLeft="10dp" 
        android:layout_marginRight="10dp" 
        android:layout_marginBottom="10dp" 
        android:background="@drawable/bg_border" 
        android:visibility="gone" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:gravity="center" > 






       </RelativeLayout> 

<Button 
    android:id="@+id/done_btn" 
    android:background="#F93249" 
    android:textColor="#ffffff" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="done"/> 

      </LinearLayout> 

     </LinearLayout> 
    </ScrollView> 




</RelativeLayout> 

Activitiy:

lower_lay = (RelativeLayout) findViewById(R.id.relative_layout);//lower layout 
     upper_lay= (RelativeLayout) findViewById(R.id.relative_layout_two);//upperlayout 
    upper.setOnClickListener(new OnClickListener() { 
     @Override 
     public void onClick(View view) { 

      lower_lay.setVisibility(View.GONE); 
      upper.setTextColor(Color.parseColor("#F93249")); 
      lower.setTextColor(Color.parseColor("#ffffff")); 
      upper_lay.setVisibility(View.VISIBLE); 

      sheetdetails.clear(); 

     } 
    }); 

    lower.setOnClickListener(new OnClickListener() { 
     @Override 
     public void onClick(View view) { 

     upper_lay.setVisibility(View.GONE); 
      upper.setTextColor(Color.parseColor("#ffffff")); 
      lower.setTextColor(Color.parseColor("#F93249")); 
      lower_lay.setVisibility(View.VISIBLE); 

     } 
    }); 
+0

Где вы инициализируете relative_layout_two? – IgorB

+0

@IgorB см. Мой отредактированный пост. Я включил эти макеты –

+0

Я все еще не вижу этого. – IgorB

ответ

1

Попробуйте использовать View.GONE не view.GONE

и lower.setOnClickListener не lower.setOnTouchListener

+0

, пожалуйста, см. мой отредактированный пост, он не работает для меня –

0

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

upper.setOnClickListener(new OnClickListener() { 

    @Override 
    public void onClick(View v) { 
     // TODO Auto-generated method stub 
     lower_lay.setVisibility(View.GONE); 
     upper.setTextColor(Color.parseColor("#F93249")); 
     lower.setTextColor(Color.parseColor("#ffffff")); 
     upper_lay.setVisibility(View.VISIBLE); 

    } 
}); 

lower.setOnClickListener(new OnClickListener() { 

    @Override 
    public void onClick(View v) { 
     // TODO Auto-generated method stub 
     lower_lay.setVisibility(View.VISIBLE); 
     upper.setTextColor(Color.parseColor("#ffffff")); 
     lower.setTextColor(Color.parseColor("#F93249")); 
     upper_lay.setVisibility(View.GONE); 
    } 
}); 
0

Я дам вам хороший совет о макете:

из чата Гаазе блога:

RelativeLayout является очень удобной планировкой в ​​использовании, поскольку она позволяет разработчикам определить, как содержимое должно быть размещено относительно другого содержимого . Во многих ситуациях это необходимо и может быть лучшим решением для работы с . Однако важно понимать, что RelativeLayout - дорогое решение, потому что для его выполнения требуются два прохода измерений , чтобы обеспечить правильное управление всеми форматами . Более того, эта проблема связывает с каждым дополнительным RelativeLayout по всей иерархии. Представьте себе RelativeLayout в верхней части иерархии вашего представления; это по существу удваивает работу по измерению всей иерархии вашего представления. Теперь представьте еще один RelativeLayout как один из детей этого первого один - это снова удваивает пройденные им измерения, , требующие четырех проходов для всех видов в своей иерархии .

Используйте различные типы макетов для ситуаций, которые не требуют возможностей RelativeLayout , таких как LinearLayout или даже настраиваемого макета . Или для ситуаций, в которых необходимо относительное выравнивание дочерних представлений , рассмотрим более оптимизированный GridLayout, который предварительно обрабатывает отношения дочернего вида и избегает проблемы с двойным измерением .

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