2016-05-18 4 views
0

Androidのマテリアルデザインを使用して視差効果を作成しようとしています。 は私がRecyclerViewがスクロールアップされ、ツールバーおよびその逆を非表示にしたかった...メインのXMLコードの下にAndroidで視差効果が機能しないMaterial Design

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context="com.mydomain.filterlistview.MainActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="180dp" 
     android:fitsSystemWindows="true"> 

     <android.support.design.widget.CollapsingToolbarLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:fitsSystemWindows="true" 
      app:contentScrim="?attr/colorPrimary" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/toolbar" 
       android:minHeight="0dp" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       app:layout_collapseMode="pin" 
       app:popupTheme="@style/AppTheme.PopupOverlay"/> 

     </android.support.design.widget.CollapsingToolbarLayout> 
    </android.support.design.widget.AppBarLayout> 

    <!--<android.support.v7.widget.SearchView--> 
     <!--android:id="@+id/search_view"--> 
     <!--android:layout_width="match_parent"--> 
     <!--android:layout_height="wrap_content" />--> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/recycler_view" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginBottom="5dp" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 

</android.support.design.widget.CoordinatorLayout> 

を参照してください。しかし、これは起こっていない。

以下は私のbuild.gradleが..です

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    testCompile 'junit:junit:4.12' 
    compile 'com.android.support:appcompat-v7:23.2.1' 
    compile 'com.android.support:recyclerview-v7:23.2.1' 
    compile 'com.android.support:cardview-v7:23.2.1' 
    compile 'com.android.support:design:23.2.1' 
} 

Android Material Design Android Material Design

答えて

0

あなたは上記のcom.android.support:recyclerview-v7:22.2.0かを使用していることを確認してください!

0

このコードは私にとって役に立ちます。

activity_main.xml

<?xml version="1.0" encoding="utf-8"?> 
 
<android.support.design.widget.CoordinatorLayout 
 
    xmlns:android="http://schemas.android.com/apk/res/android" 
 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
 
    xmlns:tools="http://schemas.android.com/tools" 
 
    android:layout_width="match_parent" 
 
    android:layout_height="match_parent" 
 
    android:fitsSystemWindows="true" 
 
    > 
 

 
    <android.support.design.widget.AppBarLayout 
 
     android:layout_width="match_parent" 
 
     android:layout_height="180dp" 
 
     android:fitsSystemWindows="true"> 
 

 
     <android.support.design.widget.CollapsingToolbarLayout 
 
      android:layout_width="match_parent" 
 
      android:layout_height="match_parent" 
 
      android:fitsSystemWindows="true" 
 
      app:contentScrim="?attr/colorPrimary" 
 
      app:layout_scrollFlags="scroll|exitUntilCollapsed"> 
 

 
      <android.support.v7.widget.Toolbar 
 
       android:id="@+id/toolbar" 
 
       android:minHeight="0dp" 
 
       android:layout_width="match_parent" 
 
       android:layout_height="?attr/actionBarSize" 
 
       app:layout_collapseMode="pin" 
 
       /> 
 

 
     </android.support.design.widget.CollapsingToolbarLayout> 
 
    </android.support.design.widget.AppBarLayout> 
 

 
    <!--<android.support.v7.widget.SearchView--> 
 
    <!--android:id="@+id/search_view"--> 
 
    <!--android:layout_width="match_parent"--> 
 
    <!--android:layout_height="wrap_content" />--> 
 

 
    <android.support.v7.widget.RecyclerView 
 
     android:id="@+id/recycler_view" 
 
     android:layout_width="match_parent" 
 
     android:layout_height="match_parent" 
 
     android:layout_marginBottom="5dp" 
 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 
 

 
</android.support.design.widget.CoordinatorLayout>

MainActivity.java

public class MainActivity extends AppCompatActivity { 
private RecyclerView mRecycler ; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    mRecycler = (RecyclerView) findViewById(R.id.recycler_view); 
    LinearLayoutManager manager =new LinearLayoutManager(this); 
    mRecycler.setLayoutManager(manager); 
    MyRecyclerAdapter adapter = new MyRecyclerAdapter(this); 
    mRecycler.setAdapter(adapter); 

} 

public class MyRecyclerAdapter extends RecyclerView.Adapter<MyRecyclerAdapter.MyViewHolder>{ 
    private Context mContext ; 
    private LayoutInflater inflater; 
    public MyRecyclerAdapter(Context ctx){ 
     this.mContext = ctx; 
     inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    } 

    @Override 
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 
     View v = inflater.inflate(R.layout.recycle_item,parent,false); 
     MyViewHolder holder =new MyViewHolder(v); 
     return holder; 
    } 

    @Override 
    public void onBindViewHolder(MyViewHolder holder, int position) { 
     holder.txtView.setText("HELLO"); 
    } 

    @Override 
    public int getItemCount() { 
     return 30; 
    } 

    public class MyViewHolder extends RecyclerView.ViewHolder{ 
    private TextView txtView; 
     public MyViewHolder(View itemView) { 
      super(itemView); 
      txtView = (TextView) itemView.findViewById(R.id.text_view); 
     } 
    } 
} 
} 

のmanifest.xml

<?xml version="1.0" encoding="utf-8"?> 
 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
 
    package="com.example.naveenbm.parallaxstack"> 
 

 
    <application 
 
     android:allowBackup="true" 
 
     android:icon="@mipmap/ic_launcher" 
 
     android:label="@string/app_name" 
 
     android:supportsRtl="true" 
 
     android:theme="@style/AppTheme"> 
 
     <activity android:name=".MainActivity"> 
 
      <intent-filter> 
 
       <action android:name="android.intent.action.MAIN" /> 
 

 
       <category android:name="android.intent.category.LAUNCHER" /> 
 
      </intent-filter> 
 
     </activity> 
 
    </application> 
 

 
</manifest>

のstyles.xml

<resources> 
 

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

 
</resources>

recycler_item.xml

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

 
    <TextView 
 
     android:id="@+id/text_view" 
 
     android:layout_width="match_parent" 
 
     android:layout_height="wrap_content" 
 
     android:text="hello" 
 
     android:textSize="22sp" 
 
     android:visibility="visible" 
 
     android:textColor="#000000" 
 
     android:layout_gravity="center_horizontal" /> 
 

 
</LinearLayout>

注:私はあなたのツールバーからapp:popupTheme="@style/AppTheme.PopupOverlay"を削除し、menifestファイルにTheme.AppCompat.Light.NoActionBarとしてアプリのテーマを追加しました。

+0

plsチェックして、これがあなたのために働くことを私に教えてください。 –

+0

これは動作しますが、私はActionBarテーマを変更するのを忘れていました。しかし、私はもう一つの疑いがあります。ツールバーを完全に隠していない。 –

+0

app:layout_collapseMode =あなたのツールバーからこの行を「ピン」にしてみよう –

関連する問題