画像があるビューフリッパーがあります。私の問題は、画像(画像ビュー)が中央にないことです。私はそれを何時間も解決しましたが、残念ながら機能していません。imageview で setGravity またはgravity が見つかりません。これが私の動作しないコードです:
マイレイアウト
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ViewFlipper android:id="@+id/flipper"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:scaleType="centerInside"
android:background="#000000"
>
</ViewFlipper>
私のsrcファイルでは:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
View view = inflater.inflate(R.layout.slider_image, container, false);
viewFlipper = (ViewFlipper)view. findViewById(R.id.flipper);
desc = (TextView)view.findViewById(R.id.textDesc);
desc.setText("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur elementum " +
"libero dapibus mi semper accumsan. Vestibulum tortor diam, " +
"imperdiet in consectetur faucibus, vulputate eget turpis." +
" Nullam nec aliquet arcu. Nunc pretium nulla non nulla pulvinar " +
"ac interdum risus dictum. Morbi viverra condimentum elit sit amet lobortis.");
desc.setMovementMethod(new ScrollingMovementMethod());
for(int i=0;i<mThumbIds.length;i++)
{
setFlipperImage(mThumbIds[i]);
}
viewFlipper.setAutoStart(true);
viewFlipper.setFlipInterval(8000);
viewFlipper.setPadding(20, 10, 20,0);
viewFlipper.setInAnimation(AnimationUtils.loadAnimation(getActivity().getApplicationContext(), R.anim.view_right_in));
viewFlipper.setOutAnimation(AnimationUtils.loadAnimation(getActivity().getApplicationContext(),R.anim.view_right_out));
viewFlipper.startFlipping();
viewFlipper.setOnTouchListener(new OnTouchListener(){
public boolean onTouch(View arg0, MotionEvent arg1) {
switch (arg1.getAction()){
case MotionEvent.ACTION_DOWN:{
downXValue = arg1.getX();
break;
}
case MotionEvent.ACTION_UP:{
float currentX = arg1.getX();
if (downXValue < currentX)
{
viewFlipper.setInAnimation(AnimationUtils.loadAnimation(getActivity().getApplicationContext(), R.anim.view_right_in));
viewFlipper.setOutAnimation(AnimationUtils.loadAnimation(getActivity().getApplicationContext(),R.anim.view_right_out));
viewFlipper.showPrevious();
}
if (downXValue > currentX)
{
viewFlipper.setInAnimation(AnimationUtils.loadAnimation(getActivity().getApplicationContext(),R.anim.view_left_in));
viewFlipper.setOutAnimation(AnimationUtils.loadAnimation(getActivity().getApplicationContext(),R.anim.view_left_out));
viewFlipper.showNext();
}
break;
}
}
return true;
}
});
super.setMenuVisibility (true);
super.setHasOptionsMenu(true);
return view;
}
私の setflipper 関数:
private void setFlipperImage(int res) {
ImageView image = new ImageView(getActivity().getApplicationContext());
image.setBackgroundResource(res);
@SuppressWarnings("deprecation")
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
layoutParams.gravity = Gravity.CENTER_HORIZONTAL;
image.setLayoutParams(layoutParams);
image.setMaxHeight(350);
image.setMaxWidth(600);
image.setAdjustViewBounds(true);
image.getLayoutParams().height = 350;
image.getLayoutParams().width = 350;
viewFlipper.addView(image);
}
どんな助けでも大歓迎です。