Androidでスライドアップ/ダウンアニメーションを使用してビューを表示および非表示にする方法は?
この例は、Androidで上下のスライドアニメーションを使用してビューを表示および非表示にする方法を示しています。
ステップ1 − Android Studioで新しいプロジェクトを作成し、[ファイル]⇒[新しいプロジェクト]に移動して、新しいプロジェクトを作成するために必要なすべての詳細を入力します。
ステップ2 −次のコードをres / layout/activity_main.xmlに追加します。
<?xml version = "1.0" encoding = "utf-8"?> <RelativeLayout xmlns:android = "https://schemas.android.com/apk/res/android" xmlns:tools = "https://schemas.android.com/tools" android:layout_width = "match_parent" android:layout_height = "match_parent"> <Button android:id = "@+id/button" android:layout_centerHorizontal = "true" android:layout_marginTop = "100dp" android:layout_width = "150dp" android:text = "Click" android:layout_height = "wrap_content"/> <LinearLayout android:id = "@+id/view" android:background = "#a6e1aa" android:orientation = "vertical" android:layout_alignParentBottom = "true" android:layout_width = "match_parent" android:layout_margin = "20dp" android:layout_height = "200dp"> <EditText android:hint = "User name" android:layout_width = "match_parent" android:layout_height = "wrap_content" /> <EditText android:hint = "Password" android:layout_width = "match_parent" android:layout_height = "wrap_content" /> </LinearLayout> </RelativeLayout>
上記のコードでは、アニメーションで線形レイアウトを表示/非表示にするボタンを使用しています。
ステップ3 −次のコードをsrc / MainActivity.java
に追加しますpackage com.example.andy.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.LinearLayout;
public class MainActivity extends AppCompatActivity {
boolean opened;
LinearLayout view;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
view = findViewById(R.id.view);
view.setVisibility(View.INVISIBLE);
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(!opened){
view.setVisibility(View.VISIBLE);
TranslateAnimation animate = new TranslateAnimation(
0,
0,
view.getHeight(),
0);
animate.setDuration(500);
animate.setFillAfter(true);
view.startAnimation(animate);
} else {
view.setVisibility(View.INVISIBLE);
TranslateAnimation animate = new TranslateAnimation(
0,
0,
0,
view.getHeight());
animate.setDuration(500);
animate.setFillAfter(true);
view.startAnimation(animate);
}
opened = !opened;
}
});
}
} 上記のコードでは、以下に示すように、変換アニメーションを使用して線形レイアウトを表示および非表示にしています-
ビューを表示するには、次のコードを使用します-
TranslateAnimation animate = new TranslateAnimation( 0, 0, view.getHeight(), 0); animate.setDuration(500); animate.setFillAfter(true); view.startAnimation(animate); To hide the view, use the following code - TranslateAnimation animate = new TranslateAnimation( 0, 0, 0, view.getHeight()); animate.setDuration(500); animate.setFillAfter(true); view.startAnimation(animate);
アプリケーションを実行してみましょう。実際のAndroidモバイルデバイスをコンピューターに接続していると思います。 android studioからアプリを実行するには、プロジェクトのアクティビティファイルの1つを開き、ツールバーの[実行]アイコンをクリックします。オプションとしてモバイルデバイスを選択し、デフォルトの画面を表示するモバイルデバイスを確認します-
ユーザーがボタンをクリックすると、上記の画面のように表示され、同じボタンをクリックして、以下に示すようにビューを非表示にします-
-
プレゼンタービューを使用してPowerPointでメモを表示する方法
プレゼンターの専門 PowerPointで表示 つまり、1台のコンピューターでスピーカーのメモを使用してプレゼンテーションを表示し、聴衆は別のモニターでメモのないプレゼンテーションを表示できます。今日の投稿では、PowerPointプレゼンテーション中にプレゼンタービューでメモを表示する方法を紹介します。最初にプレゼンタービューを有効にすることが重要です。 PowerPointで。 PowerPointでプレゼンタービューを有効にするのは簡単です。モニターを接続するだけで、PowerPointが自動的にプレゼンタービューを設定します。 プレゼンタービューでメモを表示 PowerPointで
-
Android でファイルとアプリを非表示にする方法
スマートフォンは私たちの生活に欠かせないものになりました。携帯電話をアイデンティティの延長と見なすのは間違いではありません。私たちはあらゆる種類の情報とデータを携帯電話に保存しています。そのうちのいくつかはプライベートで機密です。また、オンライン プレゼンスを制御するさまざまなアカウントやアプリにアクセスする手段でもあります。実際、私たちのスマートフォンは非常に個人的でプライベートなデバイスです。他の誰かが私たちの電話を使用することは不快であるだけでなく、危険でもあります。彼らは、機密ファイル、個人の写真、年齢制限のある機密性の高いアプリを探し回って見つけ出す可能性があります。この人が悪意を持