gpt4 book ai didi

android - 将 SwipeView 用于布局而不是图像

转载 作者:行者123 更新时间:2023-11-29 00:41:28 30 4
gpt4 key购买 nike

我正在使用 jason fry 的 SwipeView,虽然他将它用于 ImageView ,但我正在努力用布局替换它。

目前,如果我用 TextView 替换 ImageView 就可以了,但是我如何用布局替换 Imageview感谢您的帮助

包 com.example;

import android.graphics.Typeface;
import android.text.Layout;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.example.R;
import uk.co.jasonfry.android.tools.ui.PageControl;
import uk.co.jasonfry.android.tools.ui.SwipeView;
import uk.co.jasonfry.android.tools.ui.SwipeView.OnPageChangedListener;
import android.app.Activity;
import android.os.Bundle;
import android.widget.FrameLayout;
import android.widget.ImageView;

public class MyActivity extends Activity
{
SwipeView mSwipeView;

LinearLayout ll;

@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ll = new LinearLayout(this);
ll = loadLayout();

PageControl mPageControl = (PageControl) findViewById(R.id.page_control);
mSwipeView = (SwipeView) findViewById(R.id.swipe_view);

//loadImages();

for(int i=0; i<4;i++)
{
mSwipeView.addView(new FrameLayout(this));
}

TextView i0 = new TextView(this);
TextView i1 = new TextView(this);
i0.setText("page 1");
i1.setText("page 2");

((FrameLayout) mSwipeView.getChildContainer().getChildAt(0)).addView(ll);
((FrameLayout) mSwipeView.getChildContainer().getChildAt(1)).addView(ll);

SwipeImageLoader mSwipeImageLoader = new SwipeImageLoader();

mSwipeView.setOnPageChangedListener(mSwipeImageLoader);
mSwipeView.setPageControl(mPageControl);
}

private class SwipeImageLoader implements OnPageChangedListener
{

public void onPageChanged(int oldPage, int newPage)
{
if(newPage>oldPage)//going forwards
{
if(newPage != (mSwipeView.getPageCount()-1))//if at the end, don't load one page after the end
{
TextView v = new TextView(MyActivity.this);
v.setText("page :"+(newPage+1));
((FrameLayout) mSwipeView.getChildContainer().getChildAt(newPage+1)).addView(ll);
}
if(oldPage!=0)//if at the beginning, don't destroy one before the beginning
{
((FrameLayout) mSwipeView.getChildContainer().getChildAt(oldPage-1)).removeAllViews();
}

}
else //going backwards
{
if(newPage!=0)//if at the beginning, don't load one before the beginning
{

TextView v = new TextView(MyActivity.this);
v.setText("page :"+(newPage+1));
((FrameLayout) mSwipeView.getChildContainer().getChildAt(newPage-1)).addView(ll);
}
if(oldPage != (mSwipeView.getPageCount()-1))//if at the end, don't destroy one page after the end
{
((FrameLayout) mSwipeView.getChildContainer().getChildAt(oldPage+1)).removeAllViews();
}
}

}

}

private LinearLayout loadLayout()
{
//logo
ImageView logo = new ImageView(this);
logo.setImageResource(R.drawable.image001);
logo.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));

// espace
TextView espace = new TextView(this);
espace.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
espace.setText(" ");

// wrap prest
LinearLayout wprest = new LinearLayout(this);

//Prestation
TextView txt_pres = new TextView(this);
txt_pres.setText(" Prestation n° ");
txt_pres.setTextColor(R.color.black);
// plaid
TextView plaid = new TextView(this);
plaid.setTextColor(R.color.black);
plaid.setTypeface(null, Typeface.BOLD);
plaid.setText("4558");
// -
TextView tiret = new TextView(this);
tiret.setTextColor(R.color.black);
tiret.setTypeface(null, Typeface.BOLD);
tiret.setText(" - ");
// plaid
TextView platyp = new TextView(this);
platyp.setTextColor(R.color.black);
platyp.setTypeface(null, Typeface.BOLD);
platyp.setText("ECHANGE");

wprest.addView(txt_pres);
wprest.addView(plaid);
wprest.addView(tiret);
wprest.addView(platyp);



LinearLayout ll = new LinearLayout(this);

ll.setBackgroundResource(R.color.white);
ll.setOrientation(LinearLayout.VERTICAL);
ll.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT));
ll.addView(logo);
ll.addView(espace);
ll.addView(wprest);

return ll;
}
}

最佳答案

为什么不尝试另一个 ViewPager 库,例如:

  • android-viewflow (https://github.com/pakerfeldt/android-viewflow)
  • Android-ViewPagerIndicator (https://github.com/JakeWharton/Android-ViewPagerIndicator)

因为使用它,您可以轻松自定义子布局。

我看到它是最流行的 ViewPager 库。有关更多详细信息,您可以在市场上查看我的“Android UI 模式”应用程序:https://market.android.com/details?id=com.groidify.uipatterns .有许多对开发人员有用的示例。

关于android - 将 SwipeView 用于布局而不是图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9061946/

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