2017-10-06 76 views
0

我想用滾動隱藏標題欄的整個屏幕,我已經要求全屏幕前的setContentView編程....但這一要求防止滾動視圖滾動...滾動視圖不是全屏模式滾動

下面我已經提供風格XML,和活動的代碼,其中,我要求全屏和fragment.xml之其中我對着scrollling問題

style.xml

<resources xmlns:tools="http://schemas.android.com/tools"> 

<!-- Base application theme. --> 
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
    <!-- Customize your theme here. --> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="drawerArrowStyle">@style/MyDrawerArrowToggle</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
    <item name="actionBarStyle">@style/MyTheme.ActionBar.TitleTextStyle</item> 

</style> 

<style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance"> 
    <item name="android:textColor">@color/black</item> 


</style> 

<style name="Theme.AppCompat.Light.NoActionBar.FullScreen"> 
    <item name="android:windowFullscreen">true</item> 
</style> 


<!-- Actionbar Theme --> 
<style name="ActionBar" parent="Widget.AppCompat.Light.ActionBar.Solid.Inverse"> 
    <item name="android:background">@color/colorPrimary</item> 
</style> 

<style name="MyDrawerArrowToggle" parent="Widget.AppCompat.DrawerArrowToggle"> 
    <item name="color">@color/white</item> 

</style> 

<style name="MyDrawerTitle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"> 
    <item name="color">@color/black</item> 
</style> 

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /> 

<style name="EditText.Login" parent="Widget.AppCompat.EditText"> 
    <item name="android:textColor">@android:color/black</item> 
    <item name="android:textColorHint">@android:color/darker_gray</item> 
    <item name="colorAccent">@color/colorPrimaryDark</item> 
    <item name="colorControlNormal">@color/colorPrimary</item> 
    <item name="colorControlActivated">@color/colorPrimary</item> 
</style> 

<style name="Widget.MaterialProgressBar.ProgressBar" parent="android:Widget.ProgressBar"> 
    <item name="android:indeterminateDrawable">@null</item> 
    <item name="android:minWidth">48dp</item> 
    <item name="android:maxWidth">48dp</item> 
    <item name="android:minHeight">48dp</item> 
    <item name="android:maxHeight">48dp</item> 
</style> 


<color name="black">#000000</color> 
<color name="white">#FFFFFF</color> 

Java代碼

public class MainActivity extends AppCompatActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
       WindowManager.LayoutParams.FLAG_FULLSCREEN); 
     setContentView(R.layout.activity_main); 
     changeFragment(new WelcomeFragment(), ""); 
    } 

    public void changeFragment(final Fragment fragment, final String fragmenttag) { 

     new Handler().postDelayed(new Runnable() { 
      @Override 
      public void run() { 

       FragmentManager fragmentManager = getSupportFragmentManager(); 
       FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction().addToBackStack(null); 
       fragmentTransaction.replace(R.id.frame, fragment, fragmenttag); 
       fragmentTransaction.commit(); 
       fragmentTransaction.addToBackStack(null); 
      } 
     }, 0); 

    } 

片段XML

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#FFFFFF"> 

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


     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="@dimen/margin_30dp" 
      android:layout_marginRight="@dimen/margin_30dp" 
      android:orientation="vertical"> 

      <LinearLayout 
       android:id="@+id/tv_notification" 

       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:orientation="horizontal"> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:lines="1" 
        android:padding="@dimen/margin_5dp" 
        android:text="------------------" /> 

       <TextView 

        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:padding="@dimen/margin_5dp" 
        android:text="Notification" 
        android:textColor="@color/black" /> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:padding="@dimen/margin_5dp" 
        android:text="-----------------" /> 

      </LinearLayout> 

      <TextView 
       android:id="@+id/tv_error" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:padding="@dimen/margin_5dp" 
       android:text="You Got No Notification" 
       android:visibility="gone" /> 

      <TextView 
       android:id="@+id/tv_error1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:text="----------------------------------------------------------" 
       android:visibility="gone" /> 

       <android.support.v4.widget.SwipeRefreshLayout 
        android:id="@+id/swipe_refresh" 
        android:layout_width="match_parent" 
        android:layout_height="250dp"> 

        <android.support.v4.widget.NestedScrollView 
         android:layout_width="match_parent" 
         android:layout_height="match_parent"> 

         <android.support.v7.widget.RecyclerView 
          android:id="@+id/recyclerview" 
          android:layout_width="match_parent" 
          android:layout_height="match_parent" 
          android:visibility="visible" /> 


        </android.support.v4.widget.NestedScrollView> 
       </android.support.v4.widget.SwipeRefreshLayout> 





      <LinearLayout 
       android:id="@+id/linear_main" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 

       android:layout_marginTop="@dimen/margin_20dp" 
       android:orientation="vertical" 
       android:visibility="visible"> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:gravity="center" 

        android:padding="@dimen/margin_10dp" 
        android:text="Number to Navigate to" 
        android:textColor="@color/black" 
        android:textSize="@dimen/margin_18sp" /> 

       <EditText 
        android:id="@+id/et_phone" 
        android:layout_width="match_parent" 
        android:layout_height="@dimen/margin_40dp" 
        android:layout_marginTop="@dimen/margin_5dp" 
        android:background="@drawable/ic_launcher_background" 
        android:gravity="center" 
        android:hint="Enter Number" 
        android:inputType="number" 
        android:textSize="@dimen/margin_18sp" /> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:gravity="center" 
        android:padding="@dimen/margin_10dp" 

        android:text="OR" 
        android:textColor="@color/black" 
        android:textSize="@dimen/margin_18sp" 
        android:textStyle="bold" /> 


       <TextView 
        android:id="@+id/et_contact" 
        android:layout_width="match_parent" 
        android:layout_height="@dimen/margin_40dp" 
        android:layout_marginTop="@dimen/margin_5dp" 
        android:background="@drawable/ic_launcher_background" 
        android:gravity="center" 
        android:hint="Choose From Contact" 
        android:inputType="phone" 
        android:textSize="@dimen/margin_18sp" /> 

       <android.support.v7.widget.AppCompatButton 
        android:id="@+id/btn_access" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:layout_marginBottom="@dimen/margin_20dp" 
        android:layout_marginTop="@dimen/margin_20dp" 
        android:background="@drawable/ic_launcher_background" 
        android:gravity="center" 
        android:text="@string/request_access" 
        android:textColor="@color/colorPrimary" /> 

      </LinearLayout> 
     </LinearLayout> 
    </RelativeLayout> 
</ScrollView> 
+0

讓你的滾動型**的android:fillViewport =「真」 ** –

+0

沒有工作...... – unknown

回答

2

添加此進入滾動型:

android:fillViewport="true" 

您可以將此屬性添加到您的活動:

<activity 
android:windowSoftInputMode="stateVisible|adjustResize" 
.... 
/> 
+0

沒有運氣穆罕默德 – unknown

+0

它不工作? –

+0

嘗試在父級上嵌套滾動查看。 –