0
は私のメインのレイアウトは、次のように2つの線形レイアウトで構成されて
場合1つのレイアウトと1つのアクティビティで指タッチ機能を分離する方法は?</p> <p><strong>のres /レイアウト/ main.xml</strong>:
public class MainActivity extends Activity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
私は希望:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<TextView
android:text="red"
android:gravity="center_horizontal"
android:background="#aa0000"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<TextView
android:text="blue"
android:gravity="center_horizontal"
android:background="#0000aa"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<TextView
android:text="yellow"
android:gravity="center_horizontal"
android:background="#aaaa00"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<TextView
android:text="row one"
android:textSize="15pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:text="row two"
android:textSize="15pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:text="row three"
android:textSize="15pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
マイアクティビティクラスは次のようになります上の線形レイアウト(色を含む)が指のタッチでコンテンツを動かすことができるようなフィーチャを実装したいのですが、それはOnTouchListener
を実装する必要がありますが、いくつかのTextViewを感じる)私は指のタッチの機能を持っていません。
私は1つのXMLレイアウトファイルにあり、1つのJavaクラス(MainActivity.java)を持っているので、半分のレイアウトでそれらを分けることができますが、指のタッチ機能はありますが、onTouchListener
をメインアクティビティクラス全体に実装しますか?
これは、特定のビューのontouchlistenerを1つのxmlファイルで定義され、アクティビティJavaクラスで参照されるように設定する方法です。 – Leem
android:idをlinearlayoutまたはタッチリスナーで表示する任意の他のビューに与え、そのビューでタッチリスナーを設定してください –