2016-12-13 7 views
0

私はアンドロイドの初心者です。私は与えられたアドバイスに従っており、layout_heightをwrap_contentに設定しました。 私は何が間違っていますか?私のコードのフォローのスニペット:MainActivity.javaはスクロールするとRecyclerViewのアイテムの高さが正しく設定されていません

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     /*this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
     this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
       WindowManager.LayoutParams.FLAG_FULLSCREEN);*/ 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     mToolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(mToolbar); 

     // Layout manager that allows the user to flip through the pages 
     ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager); 

     // getSupportFragmentManager allows use to interact with the fragments 
     // MyFragmentPagerAdapter will return a fragment based on an index that is passed 
     viewPager.setAdapter(new MyFragmentPagerAdapter(getSupportFragmentManager(), 
       MainActivity.this)); 

     // Initialize the Sliding Tab Layout 
     SlidingTabLayout slidingTabLayout = (SlidingTabLayout) findViewById(R.id.sliding_tabs); 

     slidingTabLayout.setCustomTabView(R.layout.tab_indicator); 
     // Connect the viewPager with the sliding tab layout 
     slidingTabLayout.setViewPager(viewPager); 

    } 

activity_mainが

<LinearLayout 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:orientation="vertical"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="@color/colorPrimary" /> 
     <!--app:theme="@style/ActionBarThemeOverlay" />--> 
    <!--app:popupTheme="@style/ThemeOverlay.AppCompat.Light"--> 

    <!-- The sliding tab --> 
    <com.src.xxx.stab.SlidingTabLayout 
     android:id="@+id/sliding_tabs" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/colorPrimary" /> 

    <!--android:layout_below="@+id/app_bar"--> 

    <!-- The pager that allows us to swipe between fragments --> 
    <android.support.v4.view.ViewPager 
     android:id="@+id/viewpager" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@android:color/white" /> 

</LinearLayout> 

各tab_fragmentが

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:orientation="vertical"> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/drawerList" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

</RelativeLayout> 
+0

私たちRecyclerView項目のうちのレイアウトを示し、またRecyclerViewアダプタのコード –

+0

'height属性でwrap_content'は常にいくつかの問題を引き起こすことが起こっている。してください一定の値や 'match_parent'や重みを試してみてください。 – Talha

答えて

2

あなたがラップ内容を設定した場合、高さはに基づいて設定されますが含まれているが含まれて含まれていますデータ、固定高さが必要な場合は、dpで固定高さを設定します。例:

android:layout_height="50dp" 
1

行の高さは、行ごとに同じ高さになるように一定に保つ必要があります(例:折り返し内容ではなく20dp)。

関連する問題