네비게이션 바에서 메뉴바를 누르면 룰렛이 포함된 화면을 뜨게 하고싶습니다.
그래서 코드를 이런식으로 짯는데요
appcompatactivity랑 fragment를 동시에 상속받아야하다 보니까
public class nav_2 extends AppCompatActivity implements Fragment
이렇게 짯는데 fragment를 제대로 상속받지 못해서 자꾸 오류가 나네요 ㅠㅜ
고수님들 도움좀 부탁드립니다!ㅠ
package com.example.tf;
import android.app.Fragment;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.Button;
import android.widget.ImageView;
public class nav_2 extends AppCompatActivity implements Fragment {
View v;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
v = inflater.inflate(R.layout.nav_2,container,false);
return v;
}
private ImageView wheel;
private Bitmap mBitMap;
private float init_angle = 0.0f;
private final int IMG_DP = 300;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sel3);
wheel = (ImageView) findViewById(R.id.wheel);
mBitMap = BitmapFactory.decodeResource(getResources(), R.drawable.roulette);
wheel.setImageBitmap(onResizeImage(mBitMap));
Button btn = (Button) findViewById(R.id.rotate_btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onWheelImage();
}
});
}
public static float convertDpToPixel(float dp, Context context) {
Resources resources = context.getResources();
DisplayMetrics metrics = resources.getDisplayMetrics();
float px = dp * (metrics.densityDpi / 160f);
return px;
}
private Bitmap onResizeImage(Bitmap bitmap) {
int height = bitmap.getHeight();
int width = bitmap.getWidth();
Float size = convertDpToPixel(IMG_DP, getApplicationContext());
Bitmap resized = null;
while (height > size.intValue()) {
resized = Bitmap.createScaledBitmap(bitmap, (width * size.intValue()) / height, size.intValue(), true);
height = resized.getHeight();
width = resized.getWidth();
}
return resized;
}
private int getRandom(int maxNumber) {
return (int) (Math.random() * maxNumber);
}
private void onWheelImage() {
runOnUiThread(new Runnable() {
@Override
public void run() {
float fromAngle = getRandom(360) + 2160 + init_angle;
RotateAnimation rAnim = new RotateAnimation(init_angle, fromAngle, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
init_angle = fromAngle;
rAnim.setDuration(3000);
rAnim.setFillEnabled(true);
rAnim.setFillAfter(true);
wheel.startAnimation(rAnim);
}
});
}
}