2012-10-17 9 views
6

मेरे पास ToggleButton है। मैं इस बटन पर क्लिक करने के लिए और जगह लेना चाहता हूं। अगर मैं layout_width, layout_height आदि जोड़ता हूं तो छवि खराब दिखती है। मैंने android:padding का उपयोग करने का भी प्रयास किया लेकिन इससे मेरी मदद नहीं हुई।मैं नियंत्रण के लिए स्पर्श क्षेत्र कैसे बढ़ा सकता हूं (ToggleButton)?

उपयोगकर्ताओं की सुविधा के लिए इसकी आवश्यकता है।

enter image description here

+1

की स्थापना द्वारा स्पर्श क्षेत्र में वृद्धि कर सकते हैं कि समस्या क्या है, तो है आप उपयोग कर रहे हैं गद्दी? – Syn3sthete

+0

टचडिलेगेट आज़माएं, यहां एक उदाहरण है कि इसका उपयोग कैसे करें http://stackoverflow.com/questions/1343222/is-there-an-example-of-how-to-use-a-touchdelegate-in-android-to- वृद्धि-द-सिज़/1343796 # 1343796 – ammar26

उत्तर

3

आसान समाधान: यदि आपके पास बटन के लिए छवि है, तो इसके चारों ओर पारदर्शी क्षेत्र बनाएं (यानी स्पर्श क्षेत्र के लिए)।

भूरे रंग का क्षेत्र स्पर्श क्षेत्र को बढ़ाने के लिए पारदर्शी हो सकता है।

enter image description here

या TouchDelegate

0

अपने parent layout से margin अपने Button की (padding के स्थान पर) ले लो और फिर बटन में स्पर्श घटना डालने के बजाय अपने Layout

mLayout.setonTouchListener(View.onTouchListener{ 
    // here your working code 
}); 
2

पर opration प्रदर्शन लेआउट में रख केवल बटन को containg .. और अपनी इच्छा के रूप में लेआउट के आकार को ठीक करें

3

TouchDelegate अपने 0 के लिए उपयोग करेंके रूप में ammar26 ने आपको टिप्पणी की है।

या

इस प्रयास करें:

LinearLayout या RelativeLayout कि ToggleButton कवर की तरह एक माता पिता लेआउट बनाओ। और अब उस अभिभावक लेआउट में मार्जिन डालें।

अब, उस अभिभावक लेआउट के क्लिक पर टॉगल बटन के लिए कार्रवाई करें।

आशा है कि यह आपके दृश्य के लिए स्पर्श क्षेत्र को बढ़ाने में आपकी सहायता करेगा।

हैप्पी कोडिंग।

+0

आपका दूसरा दृष्टिकोण टचडिलेगेट कैसे काम करता है उतना ही कम है। टॉगलबटन के अभिभावक टच इवेंट्स के लिए सुनेंगे: यदि कोई निर्दिष्ट सीमाओं के भीतर है तो क्लिक टचलेगेट द्वारा टॉगल बटन पर अग्रेषित किया जाएगा –

2

वृद्धि android:padding के मूल्यों का उपयोग:

<SeekBar android:id="@+id/seek" android:layout_width="0dip" 
android:layout_height="wrap_content" android:layout_weight="1" 
android:paddingTop="5dp" android:paddingBottom="5dp" 
android:progressDrawable="@drawable/green_scrubber_progress_horizontal_holo_ligh‌​t" 
android:thumb="@drawable/thumb" /> 
3

तुम भी touch delegatesAndroid Developer Training Blog Post

public class MainActivity extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     // Get the parent view 
     View parentView = findViewById(R.id.parent_layout); 

     parentView.post(new Runnable() { 
      // Post in the parent's message queue to make sure the parent 
      // lays out its children before you call getHitRect() 
      @Override 
      public void run() { 
       // The bounds for the delegate view (an ImageButton 
       // in this example) 
       Rect delegateArea = new Rect(); 
       ImageButton myButton = (ImageButton) findViewById(R.id.button); 
       myButton.setEnabled(true); 
       myButton.setOnClickListener(new View.OnClickListener() { 
        @Override 
        public void onClick(View view) { 
         Toast.makeText(MainActivity.this, 
           "Touch occurred within ImageButton touch region.", 
           Toast.LENGTH_SHORT).show(); 
        } 
       }); 

       // The hit rectangle for the ImageButton 
       myButton.getHitRect(delegateArea); 

       // Extend the touch area of the ImageButton beyond its bounds 
       // on the right and bottom. 
       delegateArea.right += 100; 
       delegateArea.bottom += 100; 

       // Instantiate a TouchDelegate. 
       // "delegateArea" is the bounds in local coordinates of 
       // the containing view to be mapped to the delegate view. 
       // "myButton" is the child view that should receive motion 
       // events. 
       TouchDelegate touchDelegate = new TouchDelegate(delegateArea, 
         myButton); 

       // Sets the TouchDelegate on the parent view, such that touches 
       // within the touch delegate bounds are routed to the child. 
       if (View.class.isInstance(myButton.getParent())) { 
        ((View) myButton.getParent()).setTouchDelegate(touchDelegate); 
       } 
      } 
     }); 
    } 
}