android viewpager listview,android – 在ViewPager的Tabbed Activity中,ListView从底部开始显示...

我有一个Tabbed Activity有三个ListView片段,但ListView看起来从buttom切割.你永远不会看到最后一个元素.

948ae9192c7af974558c7bbd8bb4230b.png

我尝试了一切,但我无法解决它.

这是选项卡式活动:

public class TabbedActivity extends AppCompatActivity {

private SectionsPagerAdapter mSectionsPagerAdapter;

private ViewPager mViewPager;

private String query_id;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_tabbed);

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

setSupportActionBar(toolbar);

mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

mViewPager = (ViewPager) findViewById(R.id.container);

mViewPager.setAdapter(mSectionsPagerAdapter);

TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);

tabLayout.setupWithViewPager(mViewPager);

query_id = getIntent().getStringExtra("query_id");

String title = getIntent().getStringExtra("title");

setTitle(title);

}

public class SectionsPagerAdapter extends FragmentPagerAdapter {

public SectionsPagerAdapter(FragmentManager fm) {

super(fm);

}

@Override

public int getCount() {

return 3;

}

@Override

public Fragment getItem(int position) {

switch (position) {

case 0:

return AFragment.newInstance(0, "A", query_id);

case 1:

return BFragment.newInstance(1, "B", query_id);

case 2:

return CFragment.newInstance(2, "C", query_id);

}

return null;

}

@Override

public CharSequence getPageTitle(int position) {

switch (position) {

case 0:

return "A";

case 1:

return "B";

case 2:

return "C";

}

return null;

}

}

}

这是选项卡式活动布局:

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:id="@+id/main_content"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:fitsSystemWindows="true"

tools:context="com.domain.app.TabbedActivity">

android:id="@+id/appbar"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:paddingTop="@dimen/appbar_padding_top"

android:theme="@style/AppTheme.AppBarOverlay">

android:id="@+id/toolbar"

android:layout_width="match_parent"

android:layout_height="?attr/actionBarSize"

android:background="?attr/colorPrimary"

app:layout_scrollFlags="scroll|enterAlways"

app:popupTheme="@style/AppTheme.PopupOverlay">

android:id="@+id/tabs"

android:layout_width="match_parent"

android:layout_height="wrap_content" />

android:id="@+id/container"

android:layout_width="match_parent"

android:layout_height="match_parent"

app:layout_behavior="@string/appbar_scrolling_view_behavior" />

在ViewPager中,我加载ListView布局:

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical" >

android:id="@android:id/list"

android:layout_width="match_parent"

android:layout_height="match_parent" >

感谢大家!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值