Android
 Computer >> コンピューター >  >> プログラミング >> Android

スクロール可能なtextViewAndroidアプリを作成するにはどうすればよいですか?


この例は、Androidアプリでスクロール可能なtextViewを作成する方法を示しています。

ステップ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:id="@+id/activity_main"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:padding="5dp"
   tools:context=".MainActivity">
   <TextView
      android:id="@+id/textView"
      android:layout_width="wrap_content"
      android:layout_height="match_parent"
      android:scrollbars="vertical" />
</RelativeLayout>

ステップ3 −次のコードをsrc / MainActivity.java

に追加します
package app.com.sample;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      TextView textView = (TextView) findViewById(R.id.textView);
      String para = "Mohandas Karamchand Gandhi (/ˈɡɑːndi, ˈɡændi/;[2] Hindustani: [ˈmoːɦəndaːs ˈkərəmtʃənd ˈɡaːndʱi] (About this soundlisten);
         2 October 1869 – 30 January 1948) was an Indian activist who was the leader of the Indian independence movement against British colonial rule.[3]
         Employing nonviolent civil disobedience, Gandhi led India to independence and inspired movements for civil rights and freedom across the world.
         The honorific Mahātmā (Sanskrit: \"high-souled\", \"venerable\")[4] was applied to him first in 1914 in South Africa[5] and is now used worldwide.
         In India, he was also called Bapu, a term that he preferred[6] (Gujarati: endearment for father,[7] papa[7][8]), and Gandhi ji, and is known as the Father of the
         Nation.[9][10]\n" + "\n" + "Born and raised in a Hindu family in coastal Gujarat, western India, and trained in law at the Inner Temple, London, Gandhi first
         employed nonviolent civil disobedience as an expatriate lawyer in South Africa, in the resident Indian community's struggle for civil rights. After his return
         to India in 1915, he set about organising peasants,  farmers, and urban labourers to protest against excessive land-tax and discrimination.
         Assuming leadership of the Indian National Congress in 1921, Gandhi led nationwide campaigns for various social causes and for achieving Swaraj or
         self-rule.[11]\n" + "\n" + "Gandhi led Indians in challenging the British-imposed salt tax with the 400 km (250 mi) Dandi Salt March in 1930, and
         later in calling for the British to Quit India in 1942. He was imprisoned for many years, upon many occasions, in both South Africa and India.
         He lived modestly in a self-sufficient residential community and wore the traditional Indian dhoti
         and shawl, woven with yarn hand-spun on a charkha. He ate simple vegetarian food, and also undertook long fasts as a means of both
         self-purification and political protest.\n" + "\n" + "Gandhi's vision of an independent India based on religious pluralism was challenged in
         the early 1940s by a new Muslim nationalism which was demanding a separate Muslim homeland carved out of India.[12] In August 1947, Britain
         granted independence, but the British Indian Empire[12] was partitioned into two dominions, a Hindu-majority India and Muslim-majority Pakistan.[13]
         As many displaced Hindus, Muslims, and Sikhs made their way to their new lands, religious violence broke out, especially in the Punjab and Bengal.
         Eschewing the official celebration of independence in Delhi, Gandhi visited the affected areas, attempting to provide solace. In the months following,
         he undertook several fasts unto death to stop religious violence. The last of these, undertaken on 12 January 1948 when he was 78,[14] also had
         the indirect goal of pressuring India to pay out some cash assets owed to Pakistan.[14] Some Indians thought Gandhi was too accommodating.[14][15]
         Among them was Nathuram Godse, a Hindu nationalist, who assassinated Gandhi on 30 January 1948 by firing three bullets into his chest.[15";
      textView.setText(para);
      textView.setMovementMethod(newScrollingMovementMethod());
   }

ステップ4 −次のコードをandroidManifest.xmlに追加します

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="https://schemas.android.com/apk/res/android" package="app.com.sample">
   <application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:supportsRtl="true"
      android:theme="@style/AppTheme">
      <activity android:name=".MainActivity">
         <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
         </intent-filter>
      </activity>
   </application>
</manifest>

アプリケーションを実行してみましょう。実際のAndroidモバイルデバイスをコンピューターに接続していると思います。 android studioからアプリを実行するには、プロジェクトのアクティビティファイルの1つを開き、ツールバーの[実行]アイコンをクリックします。オプションとしてモバイルデバイスを選択し、デフォルトの画面を表示するモバイルデバイスを確認します-

スクロール可能なtextViewAndroidアプリを作成するにはどうすればよいですか?


  1. FacebookでAndroidアプリを作成する方法は?

    この例は、FacebookでAndroidアプリを作成する方法を示しています。FacebookアプリIDを取得するには、Facebook開発者サイトでFacebookアプリを作成する必要があります。次の手順を1つずつ実行してください。 https://developers.facebook.com/にアクセスして、新しいアプリを追加します。 ステップ1 -指定されたフィールドにアプリ名とメールアドレスを入力します ステップ2 –以下の行build.gradle/mavenを追加します Maven中央リポジトリからSDKをダウンロードします: buildscript { reposi

  2. AndroidアプリでマルチレベルのListViewを作成するにはどうすればよいですか?

    この例は、AndroidでマルチレベルのlistViewを作成する方法を示しています。 ステップ1 − Android Studioで新しいプロジェクトを作成し、[ファイル]⇒[新しいプロジェクト]に移動して、新しいプロジェクトを作成するために必要なすべての詳細を入力します。 ステップ2 −次のコードをres / layout/activity_main.xmlに追加します。 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http