Androidで画像をスムーズに回転させる方法は?
この例は、Androidで画像をスムーズに回転させる方法を示しています。
ステップ1 -Android Studioで新しいプロジェクトを作成し、[ファイル]⇒[新しいプロジェクト]に移動して、新しいプロジェクトを作成するために必要なすべての詳細を入力します。
ステップ2 -次のコードをres/layout/activity_main.xmlに追加します。
<?xml version = "1.0" encoding = "utf-8"?> <LinearLayout xmlns:android = "https://schemas.android.com/apk/res/android" android:id = "@+id/parent" xmlns:tools = "https://schemas.android.com/tools" android:layout_width = "match_parent" android:layout_height = "match_parent" tools:context = ".MainActivity" android:gravity = "center" android:orientation = "vertical"> <TextView android:id = "@+id/text" android:textSize = "18sp" android:textAlignment = "center" android:text = "rorate image" android:layout_width = "match_parent" android:layout_height = "wrap_content" /> <ImageView android:id = "@+id/rotateImage" android:layout_width = "match_parent" android:layout_marginTop = "10dp" android:layout_height = "wrap_content" android:src = "@mipmap/ic_launcher" android:layerType = "software" /> </LinearLayout>
上記のコードでは、テキストビューと画像ビューを使用しています。テキストビューをクリックすると、画像が反時計方向に回転します。
ステップ3 -次のコードをsrc/MainActivity.java
に追加しますpackage com.example.andy.myapplication;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
int view = R.layout.activity_main;
TextView text;
ImageView image;
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(view);
text = findViewById(R.id.text);
image = findViewById(R.id.rotateImage);
text.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
RotateAnimation rotate = new RotateAnimation(0, 180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotate.setDuration(5000);
rotate.setInterpolator(new LinearInterpolator());
image.startAnimation(rotate);
}
});
}
} 上記のコードでは、RotateAnimationクラスを使用しています。これは、Androidで事前定義されたクラスです。以下のコードを使用して画像を回転するには-
RotateAnimation rotate = new RotateAnimation(0, 180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); rotate.setDuration(5000); rotate.setInterpolator(new LinearInterpolator()); image.startAnimation(rotate);
アプリケーションを実行してみましょう。実際のAndroidモバイルデバイスをコンピューターに接続していると思います。 android studioからアプリを実行するには、プロジェクトのアクティビティファイルの1つを開き、ツールバーの[実行]アイコンをクリックします。オプションとしてモバイルデバイスを選択し、デフォルトの画面を表示するモバイルデバイスを確認します-
上記のコードでは、ユーザーがテキストビューをクリックすると初期画面が表示され、以下に示すように画像が回転します-
-
HTMLで画像をレスポンシブにする方法は?
画像をレスポンシブにするには、2つのプロパティを設定する必要があります。 タグを使用して画像を追加し、高さと最大幅のCSSスタイルを追加して応答性を高めます。たとえば、 style =height:auto; max-width:100%; 次のコードを実行して、画像をHTMLでレスポンシブにすることができます- 注 −画像の応答性を確認するには、ブラウザタブのサイズを変更します。画像のサイズが正しく変更されている場合は、レスポンシブであることを意味します。 例 <!DOCTYPE html> <html> <head>
-
Android で画像をクリップボードにコピーする方法
コピーと貼り付けは、おそらくコンピューターとスマートフォンで最も頻繁に使用される機能です .複数人で同じ内容を何度も入力する手間が省けます。現在、コンピューターに関して言えば、ほとんど何でも簡単にコピーして貼り付けることができます。テキスト、画像、ビデオ、オーディオ ファイル、ドキュメントなどの可能性があります。ただし、最近の携帯電話は高度で強力になり始めています。コンピュータができるほとんどすべてのことを行うことができます。その結果、日々のさまざまな業務を携帯電話に徐々に移行する人が増えています。 したがって、コピーと貼り付けの能力に関して両者の間に格差が存在するのは公平ではありません。