2017-04-15 33 views
0

我將「INVISIBLE」設置爲TextView,但它仍在顯示。android:將「INVISIBLE」設置爲TextView,但仍顯示

所以我試圖解決它的一些。

使用我的代碼定義的變量:

  1. findPasswordText:TextView的,我想隱藏

  2. findPasswordContainer:TextView中的家長

  3. mainViewGroup:根的ViewGroup定義在XML中

首先。

變 「有形」 到 「水漲船高」

例如:

private void hideFindPassword() { 
    this.findPasswordContainer.setVisibility(View.GONE); 
    this.mainViewGroup.requestLayout(); 
} 

二。

直接將「INVISIBLE」設置爲textview。

例如:

private void hideFindPassword() { 
    this.findPasswordText.setVisibility(View.VISIBLE); 
    this.mainViewGroup.requestLayout(); 
} 

第三。

將「INVISIBLE或GONE」設置爲兩者。

private void hideFindPassword() { 
    this.findPasswordContainer.setVisibility(View.GONE); 
    this.findPasswordText.setVisibility(View.VISIBLE); 
    this.mainViewGroup.requestLayout(); 
} 

沒有解決我的問題。

所以我需要你的幫助。

附上從實際顯示和XML代碼捕獲的圖像

  1. 圖片:設置前 「隱形」

enter image description here

  • 圖片:後設置「INVISIBLE」
  • enter image description here

  • xml文檔

    <android.support.constraint.ConstraintLayout 
        android:layout_width="match_parent" 
        android:layout_height="match_parent"> 
    <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:orientation="vertical" 
        android:id="@+id/find_password_container"> 
        <View 
         android:layout_width="0dp" 
         android:layout_height="15dp"/> 
        <TextView 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:text="@string/label_find_password" 
         android:textColor="#b6bec1" 
         android:gravity="right" 
         android:textSize="@dimen/base_font_size" 
         android:id="@+id/find_password_button"/> 
    </LinearLayout> 
    <View 
        android:layout_width="0dp" 
        android:layout_height="15dp"/> 
    <RelativeLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:id="@+id/div_layout_for_third_part"> 
        <View 
         android:layout_width="match_parent" 
         android:layout_height="1dp" 
         android:layout_centerInParent="true" 
         android:background="@color/colorNormal" /> 
        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_centerInParent="true" 
         android:background="#ffffff" 
         android:paddingLeft="5dp" 
         android:paddingRight="5dp" 
         android:text="@string/label_or" /> 
    </RelativeLayout> 
    

  • +0

    請按照此處的教程:http://www.java2s.com/Code/Android/UI/DemonstratesmakingaviewVISIBLEINVISIBLEandGONE.htm –

    回答

    0

    你試圖簡單地設置XML的TextView的知名度,無形?

    0

    你可以直接通過xml設置它..

    android:visibility="gone" 
    

    這個屬性或者添加到您的TextView或LinearLayout中&在運行時通過使用上述命令行根據您的需要

    this.findPasswordContainer.setVisibility(View.GONE); 
    
    this.findPasswordText.setVisibility(View.VISIBLE); 
    

    編程方式改變它。

    <android.support.constraint.ConstraintLayout 
        android:layout_width="match_parent" 
        android:layout_height="match_parent"> 
    <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:orientation="vertical" 
        android:visibility="gone" 
        android:id="@+id/find_password_container"> 
        <View 
         android:layout_width="0dp" 
         android:layout_height="15dp"/> 
        <TextView 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:text="@string/label_find_password" 
         android:textColor="#b6bec1" 
         android:gravity="right" 
         android:textSize="@dimen/base_font_size" 
         android:id="@+id/find_password_button"/> 
    </LinearLayout> 
    <View 
        android:layout_width="0dp" 
        android:layout_height="15dp"/> 
    <RelativeLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:id="@+id/div_layout_for_third_part"> 
        <View 
         android:layout_width="match_parent" 
         android:layout_height="1dp" 
         android:layout_centerInParent="true" 
         android:background="@color/colorNormal" /> 
        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_centerInParent="true" 
         android:background="#ffffff" 
         android:paddingLeft="5dp" 
         android:paddingRight="5dp" 
         android:text="@string/label_or" /> 
    </RelativeLayout> 
    android android-layout 
    

    BU默認視圖將會消失,說要回在某個時候調用

    this.findPasswordText.setVisibility(View.VISIBLE); 
    

    如果幫助,不要忘記,以紀念它。

    相關問題