gpt4 book ai didi

android - 如何在带点的Viewpager中显示全屏

转载 作者:行者123 更新时间:2023-11-29 20:50:17 25 4
gpt4 key购买 nike

我已经用点实现了 viewpager,但在设备中它显示如下 view pager with dots viewpager 中的第二个屏幕在滚动前可见 30%,如何解决这个问题。在此处添加我的代码,但我没有得到代码中的错误这是我的代码

public class MainActivity extends Activity {
// Declare Variables
ViewPager viewPager;
PagerAdapter adapter;
LinearLayout llDots;
TextView fbLogin, textViewText1, textView2, textView3, textView4;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the view from viewpager_main.xml
setContentView(R.layout.viewpager_main);
Typeface custom_font = Typeface.createFromAsset(getAssets(), "fonts/Candara.ttf");
llDots = (LinearLayout) findViewById(R.id.llDots);
viewPager = (ViewPager) findViewById(R.id.pager);

adapter = new ViewPagerAdapter(this);
viewPager.setAdapter(adapter);
fbLogin = (TextView) findViewById(R.id.textViewfacebook);
textViewText1 = (TextView) findViewById(R.id.textViewfacebook);
textView2 = (TextView) findViewById(R.id.textView2);
textView3 = (TextView) findViewById(R.id.textView3);
textView4 = (TextView) findViewById(R.id.textView4);

for (int i = 0; i < adapter.getCount(); i++) {
ImageButton imgDot = new ImageButton(this);
imgDot.setTag(i);
imgDot.setImageResource(R.drawable.dot_selector);
imgDot.setBackgroundResource(0);
imgDot.setPadding(5, 5, 5, 5);

LayoutParams params = new LayoutParams(30, 30);
imgDot.setLayoutParams(params);
if (i == 0)
imgDot.setSelected(true);

llDots.addView(imgDot);
}

viewPager.setOnPageChangeListener(new OnPageChangeListener() {

@Override
public void onPageSelected(int pos) {
Log.e("", "Page Selected is ===> " + pos);
for (int i = 0; i < adapter.getCount(); i++) {
if (i != pos) {
((ImageView) llDots.findViewWithTag(i))
.setSelected(false);
}
}
((ImageView) llDots.findViewWithTag(pos)).setSelected(true);
}

@Override
public void onPageScrolled(int pos, float arg1, int arg2) {

}

@Override
public void onPageScrollStateChanged(int arg0) {

}
});

}

public void facebookLogin(View v) {
Intent fbIntent = new Intent(MainActivity.this, EditProfile.class);
startActivity(fbIntent);
}

}

最佳答案

请将此布局用作您的 XML 并在您的项目中导入 VPI 库。

<RelativeLayout 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="#FFFFFF">

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

<com.viewpagerindicator.CirclePageIndicator
android:id="@+id/mc_cpi"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:radius="4dp"
android:padding="5dp"
app:strokeColor="@color/primary_dark"
app:strokeWidth="1px"
app:snap="true"
app:fillColor="@color/primary" />

</RelativeLayout>

关于android - 如何在带点的Viewpager中显示全屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29339440/

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