Reputation: 2821
I'm an android newbie and have seen similar questions here before. I have followed the given advice and set the layout_height to wrap_content without any success. What am I doing wrong? Snippets of my code follow: MainActivity.java contains
@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 contains
<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>
Each tab_fragment contains
<?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>
Upvotes: 0
Views: 1001
Reputation: 191
Just change the layout parameters of your item views (not activity_main or tab_fragment).
android:layout_height=”wrap_content”
https://medium.com/@gabri.mariotti/recyclerview-23-2-0-and-item-height-15b08eb06573
Upvotes: 1
Reputation: 161
The row height should be kept as constant in order to get same height for each rows, example 20dp instead of wrap content.
Upvotes: 1
Reputation: 532
If you set wrap content then the height would be set based on the data, if you need a fixed height set a fixed height in dp.Example
android:layout_height="50dp"
Upvotes: 2