gpt4 book ai didi

java - Android 中 Viewpager 的静态内容

转载 作者:行者123 更新时间:2023-12-02 11:27:48 25 4
gpt4 key购买 nike

我尝试了多种方法在 Activity_main.xml 中添加页脚和页眉,其中有一个 viewpager。到目前为止,当我在 View 页面上方添加标题时,它会显示在最终结果中,但页脚不会显示。这是xml代码

<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:background="@drawable/bg50"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#FF0000"
android:orientation="vertical">

</LinearLayout>

<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:tabGravity="fill"
app:tabMode="fixed"
app:tabSelectedTextColor="@color/colorAccent"
app:tabTextColor="#FFF" />

<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />


<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#FF0000"
android:orientation="vertical">

</LinearLayout>

这是 Activity

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
adapter.addFragment(new LoginFragment(), "Login");
adapter.addFragment(new RegisterFragment(), "Register");
viewPager.setAdapter(adapter);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewPager);

}

class ViewPagerAdapter extends FragmentPagerAdapter {
private final List<Fragment> mFragmentList = new ArrayList<>();
private final List<String> mFragmentTitleList = new ArrayList<>();

public ViewPagerAdapter(FragmentManager manager) {
super(manager);
}

@Override
public Fragment getItem(int position) {
return mFragmentList.get(position);
}

@Override
public int getCount() {
return mFragmentList.size();
}

public void addFragment(Fragment fragment, String title) {
mFragmentList.add(fragment);
mFragmentTitleList.add(title);
}

@Override
public CharSequence getPageTitle(int position) {
return mFragmentTitleList.get(position);
}
}

}

sreenshot of the result那么问题来了,如何在 View 分页器下方显示内容。

最佳答案

将viewpager布局高度更改为wrap_content。

或者只是将根布局更改为 <RelativeLayout>并设置将此标签添加到您的 View 寻呼机。

像这样:

<RelativeLayout>
...
<ViewPager
...
android:layout_height="match_parent"
android:layout_above="@id/your_footer_id"/>
...
</RelativeLayout>

关于java - Android 中 Viewpager 的静态内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49492720/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com