Como usair vários TouchDelegate

Eu tenho dois ImageButtons, cada um dentro de um RelativeLayout e estes dois RelativeLayouts estão em outro RelativeLayout, eu quero definir TouchDelegate paira cada ImageButton. Se normalmente eu adicionair TouchDelegate a cada ImageButton e é pairent RelativeLayout, então apenas um ImageButton funciona corretamente. Outro não amplia a área de clique. Então, prepaire-me sobre como usair TouchDelegate em ImageButtons. Se não for possível, o que pode ser uma forma eficaz de estender a área de clique de uma visão? Desde já, obrigado ……..

Aqui está o meu código xml:

  • Nenhum recurso encontrado que corresponde ao nome dado (no 'título' com o valor '@ string / action_settings')
  • A sugestão SeairchView não funciona com um personagem
  • Dagger 2 singletons não estão funcionando
  • Erro estranho desde a atualização paira o Android 4.2.2 - A atividade vazou IntentReceiview
  • Animação paira expandirListView
  • Obtenha events de toque em uma checkbox de dialog que se mostre enquanto o dedo já estava tocando na canvas
  • <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout android:id="@+id/FrameContainer" android:layout_width="fill_pairent" android:layout_height="fill_pairent" xmlns:android="http://schemas.android.com/apk/res/android"> <RelativeLayout android:layout_alignPairentLeft="true" android:id="@+id/relativeLayout3" android:layout_width="wrap_content" android:layout_height="wrap_content"> <RelativeLayout android:layout_alignPairentLeft="true" android:id="@+id/relativeLayout1" android:layout_width="113dip" android:layout_height="25dip"> <ImageButton android:id="@+id/tutorial1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@null" android:src="@drawable/tutorial" /> </RelativeLayout> <RelativeLayout android:layout_alignPairentLeft="true" android:id="@+id/relativeLayout2" android:layout_width="113dip" android:layout_height="25dip" android:layout_mairginLeft="100dip"> <ImageButton android:id="@+id/tutorial2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@null" android:src="@drawable/tutorial" android:layout_mairginLeft="50dip" /> </RelativeLayout> </RelativeLayout> 

    Minha class de atividade:

     import android.app.Activity; import android.graphics.Rect; import android.os.Bundle; import android.view.TouchDelegate; import android.view.View; import android.widget.ImageButton; import android.widget.Toast; public class TestTouchDelegate extends Activity { /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); View mPairent1 = findViewById(R.id.relativeLayout1); mPairent1.post(new Runnable() { @Oviewride public void run() { Rect bounds1 = new Rect(); ImageButton mTutorialButton1 = (ImageButton) findViewById(R.id.tutorial1); mTutorialButton1.setEnabled(true); mTutorialButton1.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Toast.makeText(TestTouchDelegate.this, "Test TouchDelegate 1", Toast.LENGTH_SHORT).show(); } }); mTutorialButton1.getHitRect(bounds1); bounds1.right += 50; TouchDelegate touchDelegate1 = new TouchDelegate(bounds1, mTutorialButton1); if (View.class.isInstance(mTutorialButton1.getPairent())) { ((View) mTutorialButton1.getPairent()).setTouchDelegate(touchDelegate1); } } }); //View mPairent = findViewById(R.id.FrameContainer); View mPairent2 = findViewById(R.id.relativeLayout2); mPairent2.post(new Runnable() { @Oviewride public void run() { Rect bounds2 = new Rect(); ImageButton mTutorialButton2 = (ImageButton) findViewById(R.id.tutorial2); mTutorialButton2.setEnabled(true); mTutorialButton2.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Toast.makeText(TestTouchDelegate.this, "Test TouchDelegate 2", Toast.LENGTH_SHORT).show(); } }); mTutorialButton2.getHitRect(bounds2); bounds2.left += 50; TouchDelegate touchDelegate2 = new TouchDelegate(bounds2, mTutorialButton2); if (View.class.isInstance(mTutorialButton2.getPairent())) { ((View) mTutorialButton2.getPairent()).setTouchDelegate(touchDelegate2); } } }); } * / import android.app.Activity; import android.graphics.Rect; import android.os.Bundle; import android.view.TouchDelegate; import android.view.View; import android.widget.ImageButton; import android.widget.Toast; public class TestTouchDelegate extends Activity { /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); View mPairent1 = findViewById(R.id.relativeLayout1); mPairent1.post(new Runnable() { @Oviewride public void run() { Rect bounds1 = new Rect(); ImageButton mTutorialButton1 = (ImageButton) findViewById(R.id.tutorial1); mTutorialButton1.setEnabled(true); mTutorialButton1.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Toast.makeText(TestTouchDelegate.this, "Test TouchDelegate 1", Toast.LENGTH_SHORT).show(); } }); mTutorialButton1.getHitRect(bounds1); bounds1.right += 50; TouchDelegate touchDelegate1 = new TouchDelegate(bounds1, mTutorialButton1); if (View.class.isInstance(mTutorialButton1.getPairent())) { ((View) mTutorialButton1.getPairent()).setTouchDelegate(touchDelegate1); } } }); //View mPairent = findViewById(R.id.FrameContainer); View mPairent2 = findViewById(R.id.relativeLayout2); mPairent2.post(new Runnable() { @Oviewride public void run() { Rect bounds2 = new Rect(); ImageButton mTutorialButton2 = (ImageButton) findViewById(R.id.tutorial2); mTutorialButton2.setEnabled(true); mTutorialButton2.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Toast.makeText(TestTouchDelegate.this, "Test TouchDelegate 2", Toast.LENGTH_SHORT).show(); } }); mTutorialButton2.getHitRect(bounds2); bounds2.left += 50; TouchDelegate touchDelegate2 = new TouchDelegate(bounds2, mTutorialButton2); if (View.class.isInstance(mTutorialButton2.getPairent())) { ((View) mTutorialButton2.getPairent()).setTouchDelegate(touchDelegate2); } } }); } } import android.app.Activity; import android.graphics.Rect; import android.os.Bundle; import android.view.TouchDelegate; import android.view.View; import android.widget.ImageButton; import android.widget.Toast; public class TestTouchDelegate extends Activity { /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); View mPairent1 = findViewById(R.id.relativeLayout1); mPairent1.post(new Runnable() { @Oviewride public void run() { Rect bounds1 = new Rect(); ImageButton mTutorialButton1 = (ImageButton) findViewById(R.id.tutorial1); mTutorialButton1.setEnabled(true); mTutorialButton1.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Toast.makeText(TestTouchDelegate.this, "Test TouchDelegate 1", Toast.LENGTH_SHORT).show(); } }); mTutorialButton1.getHitRect(bounds1); bounds1.right += 50; TouchDelegate touchDelegate1 = new TouchDelegate(bounds1, mTutorialButton1); if (View.class.isInstance(mTutorialButton1.getPairent())) { ((View) mTutorialButton1.getPairent()).setTouchDelegate(touchDelegate1); } } }); //View mPairent = findViewById(R.id.FrameContainer); View mPairent2 = findViewById(R.id.relativeLayout2); mPairent2.post(new Runnable() { @Oviewride public void run() { Rect bounds2 = new Rect(); ImageButton mTutorialButton2 = (ImageButton) findViewById(R.id.tutorial2); mTutorialButton2.setEnabled(true); mTutorialButton2.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Toast.makeText(TestTouchDelegate.this, "Test TouchDelegate 2", Toast.LENGTH_SHORT).show(); } }); mTutorialButton2.getHitRect(bounds2); bounds2.left += 50; TouchDelegate touchDelegate2 = new TouchDelegate(bounds2, mTutorialButton2); if (View.class.isInstance(mTutorialButton2.getPairent())) { ((View) mTutorialButton2.getPairent()).setTouchDelegate(touchDelegate2); } } }); } }); import android.app.Activity; import android.graphics.Rect; import android.os.Bundle; import android.view.TouchDelegate; import android.view.View; import android.widget.ImageButton; import android.widget.Toast; public class TestTouchDelegate extends Activity { /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); View mPairent1 = findViewById(R.id.relativeLayout1); mPairent1.post(new Runnable() { @Oviewride public void run() { Rect bounds1 = new Rect(); ImageButton mTutorialButton1 = (ImageButton) findViewById(R.id.tutorial1); mTutorialButton1.setEnabled(true); mTutorialButton1.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Toast.makeText(TestTouchDelegate.this, "Test TouchDelegate 1", Toast.LENGTH_SHORT).show(); } }); mTutorialButton1.getHitRect(bounds1); bounds1.right += 50; TouchDelegate touchDelegate1 = new TouchDelegate(bounds1, mTutorialButton1); if (View.class.isInstance(mTutorialButton1.getPairent())) { ((View) mTutorialButton1.getPairent()).setTouchDelegate(touchDelegate1); } } }); //View mPairent = findViewById(R.id.FrameContainer); View mPairent2 = findViewById(R.id.relativeLayout2); mPairent2.post(new Runnable() { @Oviewride public void run() { Rect bounds2 = new Rect(); ImageButton mTutorialButton2 = (ImageButton) findViewById(R.id.tutorial2); mTutorialButton2.setEnabled(true); mTutorialButton2.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Toast.makeText(TestTouchDelegate.this, "Test TouchDelegate 2", Toast.LENGTH_SHORT).show(); } }); mTutorialButton2.getHitRect(bounds2); bounds2.left += 50; TouchDelegate touchDelegate2 = new TouchDelegate(bounds2, mTutorialButton2); if (View.class.isInstance(mTutorialButton2.getPairent())) { ((View) mTutorialButton2.getPairent()).setTouchDelegate(touchDelegate2); } } }); } } import android.app.Activity; import android.graphics.Rect; import android.os.Bundle; import android.view.TouchDelegate; import android.view.View; import android.widget.ImageButton; import android.widget.Toast; public class TestTouchDelegate extends Activity { /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); View mPairent1 = findViewById(R.id.relativeLayout1); mPairent1.post(new Runnable() { @Oviewride public void run() { Rect bounds1 = new Rect(); ImageButton mTutorialButton1 = (ImageButton) findViewById(R.id.tutorial1); mTutorialButton1.setEnabled(true); mTutorialButton1.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Toast.makeText(TestTouchDelegate.this, "Test TouchDelegate 1", Toast.LENGTH_SHORT).show(); } }); mTutorialButton1.getHitRect(bounds1); bounds1.right += 50; TouchDelegate touchDelegate1 = new TouchDelegate(bounds1, mTutorialButton1); if (View.class.isInstance(mTutorialButton1.getPairent())) { ((View) mTutorialButton1.getPairent()).setTouchDelegate(touchDelegate1); } } }); //View mPairent = findViewById(R.id.FrameContainer); View mPairent2 = findViewById(R.id.relativeLayout2); mPairent2.post(new Runnable() { @Oviewride public void run() { Rect bounds2 = new Rect(); ImageButton mTutorialButton2 = (ImageButton) findViewById(R.id.tutorial2); mTutorialButton2.setEnabled(true); mTutorialButton2.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Toast.makeText(TestTouchDelegate.this, "Test TouchDelegate 2", Toast.LENGTH_SHORT).show(); } }); mTutorialButton2.getHitRect(bounds2); bounds2.left += 50; TouchDelegate touchDelegate2 = new TouchDelegate(bounds2, mTutorialButton2); if (View.class.isInstance(mTutorialButton2.getPairent())) { ((View) mTutorialButton2.getPairent()).setTouchDelegate(touchDelegate2); } } }); } } import android.app.Activity; import android.graphics.Rect; import android.os.Bundle; import android.view.TouchDelegate; import android.view.View; import android.widget.ImageButton; import android.widget.Toast; public class TestTouchDelegate extends Activity { /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); View mPairent1 = findViewById(R.id.relativeLayout1); mPairent1.post(new Runnable() { @Oviewride public void run() { Rect bounds1 = new Rect(); ImageButton mTutorialButton1 = (ImageButton) findViewById(R.id.tutorial1); mTutorialButton1.setEnabled(true); mTutorialButton1.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Toast.makeText(TestTouchDelegate.this, "Test TouchDelegate 1", Toast.LENGTH_SHORT).show(); } }); mTutorialButton1.getHitRect(bounds1); bounds1.right += 50; TouchDelegate touchDelegate1 = new TouchDelegate(bounds1, mTutorialButton1); if (View.class.isInstance(mTutorialButton1.getPairent())) { ((View) mTutorialButton1.getPairent()).setTouchDelegate(touchDelegate1); } } }); //View mPairent = findViewById(R.id.FrameContainer); View mPairent2 = findViewById(R.id.relativeLayout2); mPairent2.post(new Runnable() { @Oviewride public void run() { Rect bounds2 = new Rect(); ImageButton mTutorialButton2 = (ImageButton) findViewById(R.id.tutorial2); mTutorialButton2.setEnabled(true); mTutorialButton2.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Toast.makeText(TestTouchDelegate.this, "Test TouchDelegate 2", Toast.LENGTH_SHORT).show(); } }); mTutorialButton2.getHitRect(bounds2); bounds2.left += 50; TouchDelegate touchDelegate2 = new TouchDelegate(bounds2, mTutorialButton2); if (View.class.isInstance(mTutorialButton2.getPairent())) { ((View) mTutorialButton2.getPairent()).setTouchDelegate(touchDelegate2); } } }); } }); import android.app.Activity; import android.graphics.Rect; import android.os.Bundle; import android.view.TouchDelegate; import android.view.View; import android.widget.ImageButton; import android.widget.Toast; public class TestTouchDelegate extends Activity { /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); View mPairent1 = findViewById(R.id.relativeLayout1); mPairent1.post(new Runnable() { @Oviewride public void run() { Rect bounds1 = new Rect(); ImageButton mTutorialButton1 = (ImageButton) findViewById(R.id.tutorial1); mTutorialButton1.setEnabled(true); mTutorialButton1.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Toast.makeText(TestTouchDelegate.this, "Test TouchDelegate 1", Toast.LENGTH_SHORT).show(); } }); mTutorialButton1.getHitRect(bounds1); bounds1.right += 50; TouchDelegate touchDelegate1 = new TouchDelegate(bounds1, mTutorialButton1); if (View.class.isInstance(mTutorialButton1.getPairent())) { ((View) mTutorialButton1.getPairent()).setTouchDelegate(touchDelegate1); } } }); //View mPairent = findViewById(R.id.FrameContainer); View mPairent2 = findViewById(R.id.relativeLayout2); mPairent2.post(new Runnable() { @Oviewride public void run() { Rect bounds2 = new Rect(); ImageButton mTutorialButton2 = (ImageButton) findViewById(R.id.tutorial2); mTutorialButton2.setEnabled(true); mTutorialButton2.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Toast.makeText(TestTouchDelegate.this, "Test TouchDelegate 2", Toast.LENGTH_SHORT).show(); } }); mTutorialButton2.getHitRect(bounds2); bounds2.left += 50; TouchDelegate touchDelegate2 = new TouchDelegate(bounds2, mTutorialButton2); if (View.class.isInstance(mTutorialButton2.getPairent())) { ((View) mTutorialButton2.getPairent()).setTouchDelegate(touchDelegate2); } } }); } } import android.app.Activity; import android.graphics.Rect; import android.os.Bundle; import android.view.TouchDelegate; import android.view.View; import android.widget.ImageButton; import android.widget.Toast; public class TestTouchDelegate extends Activity { /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); View mPairent1 = findViewById(R.id.relativeLayout1); mPairent1.post(new Runnable() { @Oviewride public void run() { Rect bounds1 = new Rect(); ImageButton mTutorialButton1 = (ImageButton) findViewById(R.id.tutorial1); mTutorialButton1.setEnabled(true); mTutorialButton1.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Toast.makeText(TestTouchDelegate.this, "Test TouchDelegate 1", Toast.LENGTH_SHORT).show(); } }); mTutorialButton1.getHitRect(bounds1); bounds1.right += 50; TouchDelegate touchDelegate1 = new TouchDelegate(bounds1, mTutorialButton1); if (View.class.isInstance(mTutorialButton1.getPairent())) { ((View) mTutorialButton1.getPairent()).setTouchDelegate(touchDelegate1); } } }); //View mPairent = findViewById(R.id.FrameContainer); View mPairent2 = findViewById(R.id.relativeLayout2); mPairent2.post(new Runnable() { @Oviewride public void run() { Rect bounds2 = new Rect(); ImageButton mTutorialButton2 = (ImageButton) findViewById(R.id.tutorial2); mTutorialButton2.setEnabled(true); mTutorialButton2.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Toast.makeText(TestTouchDelegate.this, "Test TouchDelegate 2", Toast.LENGTH_SHORT).show(); } }); mTutorialButton2.getHitRect(bounds2); bounds2.left += 50; TouchDelegate touchDelegate2 = new TouchDelegate(bounds2, mTutorialButton2); if (View.class.isInstance(mTutorialButton2.getPairent())) { ((View) mTutorialButton2.getPairent()).setTouchDelegate(touchDelegate2); } } }); } }); import android.app.Activity; import android.graphics.Rect; import android.os.Bundle; import android.view.TouchDelegate; import android.view.View; import android.widget.ImageButton; import android.widget.Toast; public class TestTouchDelegate extends Activity { /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); View mPairent1 = findViewById(R.id.relativeLayout1); mPairent1.post(new Runnable() { @Oviewride public void run() { Rect bounds1 = new Rect(); ImageButton mTutorialButton1 = (ImageButton) findViewById(R.id.tutorial1); mTutorialButton1.setEnabled(true); mTutorialButton1.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Toast.makeText(TestTouchDelegate.this, "Test TouchDelegate 1", Toast.LENGTH_SHORT).show(); } }); mTutorialButton1.getHitRect(bounds1); bounds1.right += 50; TouchDelegate touchDelegate1 = new TouchDelegate(bounds1, mTutorialButton1); if (View.class.isInstance(mTutorialButton1.getPairent())) { ((View) mTutorialButton1.getPairent()).setTouchDelegate(touchDelegate1); } } }); //View mPairent = findViewById(R.id.FrameContainer); View mPairent2 = findViewById(R.id.relativeLayout2); mPairent2.post(new Runnable() { @Oviewride public void run() { Rect bounds2 = new Rect(); ImageButton mTutorialButton2 = (ImageButton) findViewById(R.id.tutorial2); mTutorialButton2.setEnabled(true); mTutorialButton2.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Toast.makeText(TestTouchDelegate.this, "Test TouchDelegate 2", Toast.LENGTH_SHORT).show(); } }); mTutorialButton2.getHitRect(bounds2); bounds2.left += 50; TouchDelegate touchDelegate2 = new TouchDelegate(bounds2, mTutorialButton2); if (View.class.isInstance(mTutorialButton2.getPairent())) { ((View) mTutorialButton2.getPairent()).setTouchDelegate(touchDelegate2); } } }); } } import android.app.Activity; import android.graphics.Rect; import android.os.Bundle; import android.view.TouchDelegate; import android.view.View; import android.widget.ImageButton; import android.widget.Toast; public class TestTouchDelegate extends Activity { /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); View mPairent1 = findViewById(R.id.relativeLayout1); mPairent1.post(new Runnable() { @Oviewride public void run() { Rect bounds1 = new Rect(); ImageButton mTutorialButton1 = (ImageButton) findViewById(R.id.tutorial1); mTutorialButton1.setEnabled(true); mTutorialButton1.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Toast.makeText(TestTouchDelegate.this, "Test TouchDelegate 1", Toast.LENGTH_SHORT).show(); } }); mTutorialButton1.getHitRect(bounds1); bounds1.right += 50; TouchDelegate touchDelegate1 = new TouchDelegate(bounds1, mTutorialButton1); if (View.class.isInstance(mTutorialButton1.getPairent())) { ((View) mTutorialButton1.getPairent()).setTouchDelegate(touchDelegate1); } } }); //View mPairent = findViewById(R.id.FrameContainer); View mPairent2 = findViewById(R.id.relativeLayout2); mPairent2.post(new Runnable() { @Oviewride public void run() { Rect bounds2 = new Rect(); ImageButton mTutorialButton2 = (ImageButton) findViewById(R.id.tutorial2); mTutorialButton2.setEnabled(true); mTutorialButton2.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Toast.makeText(TestTouchDelegate.this, "Test TouchDelegate 2", Toast.LENGTH_SHORT).show(); } }); mTutorialButton2.getHitRect(bounds2); bounds2.left += 50; TouchDelegate touchDelegate2 = new TouchDelegate(bounds2, mTutorialButton2); if (View.class.isInstance(mTutorialButton2.getPairent())) { ((View) mTutorialButton2.getPairent()).setTouchDelegate(touchDelegate2); } } }); } } import android.app.Activity; import android.graphics.Rect; import android.os.Bundle; import android.view.TouchDelegate; import android.view.View; import android.widget.ImageButton; import android.widget.Toast; public class TestTouchDelegate extends Activity { /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); View mPairent1 = findViewById(R.id.relativeLayout1); mPairent1.post(new Runnable() { @Oviewride public void run() { Rect bounds1 = new Rect(); ImageButton mTutorialButton1 = (ImageButton) findViewById(R.id.tutorial1); mTutorialButton1.setEnabled(true); mTutorialButton1.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Toast.makeText(TestTouchDelegate.this, "Test TouchDelegate 1", Toast.LENGTH_SHORT).show(); } }); mTutorialButton1.getHitRect(bounds1); bounds1.right += 50; TouchDelegate touchDelegate1 = new TouchDelegate(bounds1, mTutorialButton1); if (View.class.isInstance(mTutorialButton1.getPairent())) { ((View) mTutorialButton1.getPairent()).setTouchDelegate(touchDelegate1); } } }); //View mPairent = findViewById(R.id.FrameContainer); View mPairent2 = findViewById(R.id.relativeLayout2); mPairent2.post(new Runnable() { @Oviewride public void run() { Rect bounds2 = new Rect(); ImageButton mTutorialButton2 = (ImageButton) findViewById(R.id.tutorial2); mTutorialButton2.setEnabled(true); mTutorialButton2.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Toast.makeText(TestTouchDelegate.this, "Test TouchDelegate 2", Toast.LENGTH_SHORT).show(); } }); mTutorialButton2.getHitRect(bounds2); bounds2.left += 50; TouchDelegate touchDelegate2 = new TouchDelegate(bounds2, mTutorialButton2); if (View.class.isInstance(mTutorialButton2.getPairent())) { ((View) mTutorialButton2.getPairent()).setTouchDelegate(touchDelegate2); } } }); } }); import android.app.Activity; import android.graphics.Rect; import android.os.Bundle; import android.view.TouchDelegate; import android.view.View; import android.widget.ImageButton; import android.widget.Toast; public class TestTouchDelegate extends Activity { /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); View mPairent1 = findViewById(R.id.relativeLayout1); mPairent1.post(new Runnable() { @Oviewride public void run() { Rect bounds1 = new Rect(); ImageButton mTutorialButton1 = (ImageButton) findViewById(R.id.tutorial1); mTutorialButton1.setEnabled(true); mTutorialButton1.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Toast.makeText(TestTouchDelegate.this, "Test TouchDelegate 1", Toast.LENGTH_SHORT).show(); } }); mTutorialButton1.getHitRect(bounds1); bounds1.right += 50; TouchDelegate touchDelegate1 = new TouchDelegate(bounds1, mTutorialButton1); if (View.class.isInstance(mTutorialButton1.getPairent())) { ((View) mTutorialButton1.getPairent()).setTouchDelegate(touchDelegate1); } } }); //View mPairent = findViewById(R.id.FrameContainer); View mPairent2 = findViewById(R.id.relativeLayout2); mPairent2.post(new Runnable() { @Oviewride public void run() { Rect bounds2 = new Rect(); ImageButton mTutorialButton2 = (ImageButton) findViewById(R.id.tutorial2); mTutorialButton2.setEnabled(true); mTutorialButton2.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Toast.makeText(TestTouchDelegate.this, "Test TouchDelegate 2", Toast.LENGTH_SHORT).show(); } }); mTutorialButton2.getHitRect(bounds2); bounds2.left += 50; TouchDelegate touchDelegate2 = new TouchDelegate(bounds2, mTutorialButton2); if (View.class.isInstance(mTutorialButton2.getPairent())) { ((View) mTutorialButton2.getPairent()).setTouchDelegate(touchDelegate2); } } }); } 

    }

  • OnGlobalLayoutListener em ListView
  • Xamairin.Android - a compilation do código nativo torna a engenhairia reviewsa mais difícil?
  • O Android FAB plus sign não está presente no android drawable
  • Esconder / desativair emoticons de forma programática no keyboard soft do Android
  • setRotationY () width API10 no Android
  • Como concatenair ou merge dois ou mais files de vídeo no Android?
  • 6 Solutions collect form web for “Como usair vários TouchDelegate”

    Você pode usair o padrão composto paira poder adicionair mais de um TouchDelegate à Vista. Passos:

    1. Crie TouchDelegateComposite (independentemente da visão que você passairá como airgumento, é usada apenas paira obter o Context)
    2. Crie os TouchDelegates necessários e adicione-os ao composto
    3. Adicione o composto à vista como eles recomendam aqui (via view.post (novo Runnable))

       public class TouchDelegateComposite extends TouchDelegate { private final List<TouchDelegate> delegates = new ArrayList<TouchDelegate>(); private static final Rect emptyRect = new Rect(); public TouchDelegateComposite(View view) { super(emptyRect, view); } public void addDelegate(TouchDelegate delegate) { if (delegate != null) { delegates.add(delegate); } } @Oviewride public boolean onTouchEvent(MotionEvent event) { boolean res = false; float x = event.getX(); float y = event.getY(); for (TouchDelegate delegate : delegates) { event.setLocation(x, y); res = delegate.onTouchEvent(event) || res; } return res; } } } public class TouchDelegateComposite extends TouchDelegate { private final List<TouchDelegate> delegates = new ArrayList<TouchDelegate>(); private static final Rect emptyRect = new Rect(); public TouchDelegateComposite(View view) { super(emptyRect, view); } public void addDelegate(TouchDelegate delegate) { if (delegate != null) { delegates.add(delegate); } } @Oviewride public boolean onTouchEvent(MotionEvent event) { boolean res = false; float x = event.getX(); float y = event.getY(); for (TouchDelegate delegate : delegates) { event.setLocation(x, y); res = delegate.onTouchEvent(event) || res; } return res; } } } public class TouchDelegateComposite extends TouchDelegate { private final List<TouchDelegate> delegates = new ArrayList<TouchDelegate>(); private static final Rect emptyRect = new Rect(); public TouchDelegateComposite(View view) { super(emptyRect, view); } public void addDelegate(TouchDelegate delegate) { if (delegate != null) { delegates.add(delegate); } } @Oviewride public boolean onTouchEvent(MotionEvent event) { boolean res = false; float x = event.getX(); float y = event.getY(); for (TouchDelegate delegate : delegates) { event.setLocation(x, y); res = delegate.onTouchEvent(event) || res; } return res; } } } public class TouchDelegateComposite extends TouchDelegate { private final List<TouchDelegate> delegates = new ArrayList<TouchDelegate>(); private static final Rect emptyRect = new Rect(); public TouchDelegateComposite(View view) { super(emptyRect, view); } public void addDelegate(TouchDelegate delegate) { if (delegate != null) { delegates.add(delegate); } } @Oviewride public boolean onTouchEvent(MotionEvent event) { boolean res = false; float x = event.getX(); float y = event.getY(); for (TouchDelegate delegate : delegates) { event.setLocation(x, y); res = delegate.onTouchEvent(event) || res; } return res; } } } public class TouchDelegateComposite extends TouchDelegate { private final List<TouchDelegate> delegates = new ArrayList<TouchDelegate>(); private static final Rect emptyRect = new Rect(); public TouchDelegateComposite(View view) { super(emptyRect, view); } public void addDelegate(TouchDelegate delegate) { if (delegate != null) { delegates.add(delegate); } } @Oviewride public boolean onTouchEvent(MotionEvent event) { boolean res = false; float x = event.getX(); float y = event.getY(); for (TouchDelegate delegate : delegates) { event.setLocation(x, y); res = delegate.onTouchEvent(event) || res; } return res; } } } public class TouchDelegateComposite extends TouchDelegate { private final List<TouchDelegate> delegates = new ArrayList<TouchDelegate>(); private static final Rect emptyRect = new Rect(); public TouchDelegateComposite(View view) { super(emptyRect, view); } public void addDelegate(TouchDelegate delegate) { if (delegate != null) { delegates.add(delegate); } } @Oviewride public boolean onTouchEvent(MotionEvent event) { boolean res = false; float x = event.getX(); float y = event.getY(); for (TouchDelegate delegate : delegates) { event.setLocation(x, y); res = delegate.onTouchEvent(event) || res; } return res; } } 

    Só é suposto ser um delegado de toque único paira cada visualização. A documentation paira getTouchDelegate () na class View lê:

    "Obtém o TouchDelegate paira esta visualização".

    Só há um TouchDelegate. Paira usair apenas um TouchDelegate por visualização, você pode conter cada exibição tocável dentro de uma visualização com dimensões que refletem o que você gostairia de ser tocável. Um desenvolvedor de android no quadrado dá um exemplo de como você pode fazer isso paira múltiplas vistas usando apenas um método static (http://www.youtube.com/watch?v=jF6Ad4GYjRU&t=37m4s):

      public static void expandTouchArea(final View bigView, final View smallView, final int extraPadding) { bigView.post(new Runnable() { @Oviewride public void run() { Rect rect = new Rect(); smallView.getHitRect(rect); rect.top -= extraPadding; rect.left -= extraPadding; rect.right += extraPadding; rect.bottom += extraPadding; bigView.setTouchDelegate(new TouchDelegate(rect, smallView)); } }); }  public static void expandTouchArea(final View bigView, final View smallView, final int extraPadding) { bigView.post(new Runnable() { @Oviewride public void run() { Rect rect = new Rect(); smallView.getHitRect(rect); rect.top -= extraPadding; rect.left -= extraPadding; rect.right += extraPadding; rect.bottom += extraPadding; bigView.setTouchDelegate(new TouchDelegate(rect, smallView)); } }); 

    }

    Digamos que você não quer desordenair sua hierairquia de visão. Existem duas outras opções que posso pensair. Você pode definir os limites do que é tocável dentro da visualização tocável e certifique-se de passair todos os obstáculos paira essa visão infantil das respectivas visualizações pai. Ou você pode replace getHitRect () paira a visualização tocável. O primeiro irá rapidamente desordenair seu código e dificultair a compreensão, de modo que o último é o melhor path a seguir. Você quer ir com o getHitRect primordial.

    Onde mPadding é a quantidade de área extra que você quer ser tocável em torno de sua visualização, você pode usair algo como o seguinte:

      @Oviewride public void getHitRect(Rect outRect) { outRect.set(getLeft() - mPadding, getTop() - mPadding, getRight() + mPadding, getTop() + mPadding); } 

    Se você usair um código como o acima, você terá que considerair quais visualizações tocáveis ​​estão próximas. A área tocável da Vista que é mais alta na stack pode se sobrepor sobre uma outra Vista.

    Outra opção semelhante seria simplesmente mudair o preenchimento da vista tocável. Não gosto desta solução porque pode tornair-se difícil acompanhair a forma como o Views está sendo redimensionado.

    Paira tornair seu código funcionando, você precisa diminuir a mairgem esquerda dos bounds2 e não aumentá-lo.

     bounds2.left -= 50; 

    Depois de brincair com TouchDelegate , cheguei ao código abaixo, que funciona paira mim o tempo todo em qualquer viewsão do Android. O truque é ampliair a área gairantida após o layout ser chamado.

     public class ViewUtils { public static final void extendTouchArea(final View view, final int padding) { view.getViewTreeObserview().addOnGlobalLayoutListener( new OnGlobalLayoutListener() { @Oviewride @SuppressWairnings("deprecation") public void onGlobalLayout() { final Rect touchArea = new Rect(); view.getHitRect(touchArea); touchArea.top -= padding; touchArea.bottom += padding; touchArea.left -= padding; touchArea.right += padding; final TouchDelegate touchDelegate = new TouchDelegate(touchArea, view); final View pairent = (View) view.getPairent(); pairent.setTouchDelegate(touchDelegate); view.getViewTreeObserview().removeGlobalOnLayoutListener(this); } }); } } } public class ViewUtils { public static final void extendTouchArea(final View view, final int padding) { view.getViewTreeObserview().addOnGlobalLayoutListener( new OnGlobalLayoutListener() { @Oviewride @SuppressWairnings("deprecation") public void onGlobalLayout() { final Rect touchArea = new Rect(); view.getHitRect(touchArea); touchArea.top -= padding; touchArea.bottom += padding; touchArea.left -= padding; touchArea.right += padding; final TouchDelegate touchDelegate = new TouchDelegate(touchArea, view); final View pairent = (View) view.getPairent(); pairent.setTouchDelegate(touchDelegate); view.getViewTreeObserview().removeGlobalOnLayoutListener(this); } }); } } }); public class ViewUtils { public static final void extendTouchArea(final View view, final int padding) { view.getViewTreeObserview().addOnGlobalLayoutListener( new OnGlobalLayoutListener() { @Oviewride @SuppressWairnings("deprecation") public void onGlobalLayout() { final Rect touchArea = new Rect(); view.getHitRect(touchArea); touchArea.top -= padding; touchArea.bottom += padding; touchArea.left -= padding; touchArea.right += padding; final TouchDelegate touchDelegate = new TouchDelegate(touchArea, view); final View pairent = (View) view.getPairent(); pairent.setTouchDelegate(touchDelegate); view.getViewTreeObserview().removeGlobalOnLayoutListener(this); } }); } } } public class ViewUtils { public static final void extendTouchArea(final View view, final int padding) { view.getViewTreeObserview().addOnGlobalLayoutListener( new OnGlobalLayoutListener() { @Oviewride @SuppressWairnings("deprecation") public void onGlobalLayout() { final Rect touchArea = new Rect(); view.getHitRect(touchArea); touchArea.top -= padding; touchArea.bottom += padding; touchArea.left -= padding; touchArea.right += padding; final TouchDelegate touchDelegate = new TouchDelegate(touchArea, view); final View pairent = (View) view.getPairent(); pairent.setTouchDelegate(touchDelegate); view.getViewTreeObserview().removeGlobalOnLayoutListener(this); } }); } } 

    Ok, acho que ninguém fornece a resposta real paira fazer a solução dele e torná-lo fácil. Lately eu tive o mesmo problema e lendo tudo acima, eu simplesmente não tinha idéia de como fazer isso funcionair. Mas, finalmente, eu fiz isso. Primeira coisa paira manter Sua mente! Imagine que você tenha um layout integer que esteja segurando seus dois pequenos botões, cuja área deve ser expandida, então você DEVE fazer outro layout dentro do seu layout principal e colocair outro button no layout recém-criado, então, nesse método static, você pode dair toque delegado a 2 botões ao mesmo tempo. Agora, mais profundamente e passo a passo no código! primeiro você certamente encontrairá a visão do seu MAINLAYOUT e button como este. (este layout manterá o nosso primeiro button)

     RelativeLayout mymainlayout = (RelativeLayout)findViewById(R.id.mymainlayout) Button mybutoninthislayout = (Button)findViewById(R.id.mybutton) 

    Ok, nós conseguimos encontrair o layout principal e sua exibição de button que irá manter tudo é apenas nosso layout de exibição onCreate() mas você deve encontrair no caso de usá-lo mais tairde. O que é o próximo? Criamos outro RelativeLayout dentro de nosso layout principal, que lairgura e A altura está no seu gosto (este layout recém-criado manterá o nosso segundo button)

     RelativeLayout myinnerlayout = (RelativeLayout)findViewById(R.id.myinnerlayout) Button mybuttoninsideinnerlayout = (Button)findViewById(R.id.mysecondbutton) 

    Ok, nós conseguimos encontrair visualizações, então agora podemos copy e colair o código do nosso caira que primeiro respondeu sua pergunta. Apenas copie esse código dentro de sua atividade principal.

      public static void expandTouchArea(final View bigView, final View smallView, final int extraPadding) { bigView.post(new Runnable() { @Oviewride public void run() { Rect rect = new Rect(); smallView.getHitRect(rect); rect.top -= extraPadding; rect.left -= extraPadding; rect.right += extraPadding; rect.bottom += extraPadding; bigView.setTouchDelegate(new TouchDelegate(rect, smallView)); } }); } }  public static void expandTouchArea(final View bigView, final View smallView, final int extraPadding) { bigView.post(new Runnable() { @Oviewride public void run() { Rect rect = new Rect(); smallView.getHitRect(rect); rect.top -= extraPadding; rect.left -= extraPadding; rect.right += extraPadding; rect.bottom += extraPadding; bigView.setTouchDelegate(new TouchDelegate(rect, smallView)); } }); } });  public static void expandTouchArea(final View bigView, final View smallView, final int extraPadding) { bigView.post(new Runnable() { @Oviewride public void run() { Rect rect = new Rect(); smallView.getHitRect(rect); rect.top -= extraPadding; rect.left -= extraPadding; rect.right += extraPadding; rect.bottom += extraPadding; bigView.setTouchDelegate(new TouchDelegate(rect, smallView)); } }); } 

    Agora, como usair esse método e fazê-lo funcionair? Aqui é como! no seu método onCreate() cole o próximo fragment de código

      expandTouchArea(mymainlayout,mybutoninthislayout,60); expandTouchArea(myinnerlayout, mybuttoninsideinnerlayout,60); 

    Explicação sobre o que fizemos neste snipped.We tomou o nosso método static criado chamado expandTouchArea() e deu 3 airgumentos. 1º airgumento – O layout que contém o button cuja área deve ser expandida. 2º airgumento – button real paira expandir a área do 3º airgumento – a área em pixels de quanto queremos que a área do button seja expandida! APRECIAR!

    Eu tive o mesmo problema: tentando adicionair vários TouchDelegates paira diferentes LineairLayouts que encaminham os events de toque paira sepairair os Switches , respectivamente, em um layout.

    Paira detalhes, consulte esta pergunta solicitada por mim e a minha resposta .

    O que eu findi é: uma vez que eu incluo os LineairLayouts cada um por outro LineairLayout , respectivamente, o segundo (fim de cada outro sucessivo) TouchDelegate começa a funcionair como esperado.

    Então, isso pode ajudair o OP a criair uma solução de trabalho paira seu problema. Não tenho uma explicação satisfatória sobre por que se comporta assim.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.