Skip to main content

Android Layouts

Android Layouts  


  • Introduction to android layouts in Hindi 
  • Attributes of android layouts in Hindi 
  • Different types of android layouts in Hindi 

Introduction to Android Layouts 

जैसा की मैने आपको पहले बताया जब भी आप views क्रिएट करते है तो वो उसी order में शो होते है जिसमे आपने उन्हें क्रिएट किया है एक के बाद दूसरा। कई बार ऐसा हो सकता है की आप किसी view को screen पर एक particular position पर place करना चाहते है। ऐसा आप android layouts की मदद से कर सकते है।  

Layouts यूजर इंटरफ़ेस के लिए structure प्रोवाइड करते है उस structure के according आप अपने elements स्क्रीन पर मैनेज कर सकते है। Android system कई तरह के layouts provide करता है। आपकी एप्लीकेशन के लिए जो layout आपको ठीक लगे आप उसे यूज़ कर सकते है। 

Android में layouts आप 2 तरह से define कर सकते है या तो आप एक XML फाइल के द्वारा ऐसा कर सकते है या run time  में view और view groups के objects क्रिएट करके ऐसा कर सकते है।   
    
आप जो चाहे वो तरीका अपना सकते है या आप दोनों तरीके भी अपना सकते है। आप चाहे तो XML के द्वारा क्रिएट किये हुए layouts को run time में चेंज भी कर सकते है। यदि आप layouts XML फाइल के द्वारा डिक्लेअर करते है तो आप अपनी एप्लीकेशन के view को और एप्लीकेशन के behavior को अलग अलग control कर सकते है।

Attributes of Android Layouts

नीचे कुछ common attributes दिए जा रहे है जो सभी views के साथ यूज़ होते है।

android:id - इस attribute के द्वारा आप view की id define करते है जो view को uniquely identify करने के काम आती है।

android:layout_width - इस attribute के द्वारा आप view की screen पर width define करते है।

android:layout_height -  इस attribute के द्वारा आप view की स्क्रीन पर height define करते है।


Types of Android Layouts


Linear layout

Linear layout एक ऐसा layout है जिसमे सारे elements एक ही direction में होते है या तो vertical या horizontal. आप layout का direction android:orientation attribute के द्वारा define कर सकते है।

यदि layout का direction vertical है तो एक column में एक ही एलिमेंट आएगा। और यदि layout का direction horizontal है तो एक row में एक ही element आएगा।


यदि आप चाहे तो किसी एक particular element को priority वैल्यू भी दे सकते है। इसे layout weight कहते है।  ऐसा आप android:layout_weight attribute डिफाइन करके कर सकते है।  जिस element का जितना weight होता है वो उतना ही space screen पर cover करता है।

यदि किसी element का weight बाकि elements से अधिक है तो सभी elements के set होने के बाद जो remaining space होगा वो element cover करेगा।

Linear layout क्रिएट करने के लिए आपको XML file में <LinearLayout> element declare करना होगा। इस element के android:layout_width, android:layout_height और android:orientation 3 attributes होते है। इन तीनो attributes के लिए values provide करके आप layout को set कर सकते है।


<LinearLayout xmlns:android="android schema address"  
android:layout_width="width of layout"
android:layout_height="height of layout"
android:orientation="layout orientation">

<Button

android:layout_width="width of button"
android:layout_height="height of button"
android:text="name of button" /> 

<Button
android:layout_width="width of button"
android:layout_height="height of button"
android:text="name of button" /> 

</LinearLayout>


Relative Layout

Relative layout view elements को relative positions पर display करता है। हर view को आप दूसरे elements के relation में position कर सकते है। किसी भी नए view की position आप existing view के relation में define करते है। जैसे की आप existing element के right में नए element को set करना चाहते है या left में। इस प्रकार आप किसी भी element को screen पर कँही भी place कर सकते है।

Relative layout views को position करने के लिए कुछ attributes provide करता है, जिनके द्वारा आप अपने view को position कर सकते है। आइये इन attributes के बारे में जानने का प्रयास करते है -

android:layout_alignParentTop

यदि किसी view element में इस attribute की value true है तो वो view आप की स्क्रीन में सबसे top पर show होगा।

android:layout_centralVertical   

यदि किसी view element में इस attribute की वैल्यू true है तो वो view आप की स्क्रीन में vertically center में show होगा।

android:layout_below

ये attribute आपके view element को उस view के नीचे position करता है जो आपने resource id के द्वारा define किया है।

android:layout_toRightOf

ये attribute आपके view element को उस view element के right में place करता है जो आपने resource id के द्वारा define किया है।

यँहा पर ये कुछ उदाहरण दिए गए है ये attributes बहुत सारे है। आप जो चाहे अपनी आवश्यकता के अनुसार इस्तेमाल कर सकते है।


<RelativeLayout xmlns:android="android schema address"  
android:layout_width="width of layout"
android:layout_height="height of layout"
android:paddingLeft="in dp"
android:paddingRight="in dp">

<Button

android:layout_width="width of button"
android:layout_height="height of button"
android:layout_below="id of other view element"
andorid:text="name of button" /> 

<Button
android:layout_width="width of button"
android:layout_height="height of button"
android:layout_centralVertical="id of other view element"
android:text="name of button" /> 

</RelativeLayout>




ListView

ListView एक view group होता है जो items की list show करता है जिन्हे आप scroll कर सकते है। ये layout run time में सभी viewsको मैनेज कर सकता है। इस layout में एक ही column होता है और row बहुत सी होती है। यानी आप एक row में एक ही view position कर सकते है।

Run time में आप adapter के द्वारा किसी array या database से item को pull करते है वो adapter उस item को view convert करके list के आखिर में add कर देता है।


GridView

GridView एक view group होता है तो items को two dimensional grid में शो करता है। इस grid को आप scroll कर सकते है। इस layout में items rows और columns की form में show होते है।  GridView में items run time पर automatically insert हो जाते है।

Comments

Popular posts from this blog

Android Services

Android Services Introduction to  android services in Hindi  Declaring  services in Hindi Creating a  android service in Hindi Introduction to Android Services इससे पहले की आप जाने की service क्या होती है आइये जानते है की service क्या नहीं होती है - एक service separate प्रोसेस नहीं होती है। ये आपकी एप्लीकेशन का ही पार्ट होती है।  एक service thread नहीं होती है।  आइये अब देखते है service क्या होती है - Service एक facility होती है जिससे आप android system को बता सकते है की आप कोई काम background में करते रहना चाहते है।  Service एक facility होती है जिससे एक एप्लीकेशन अपनी कुछ functionality दूसरी applications को expose कर सकती है।    हर service क्लास का <service> declaration AndroidManifest.xml file में होना चाहिए। Services को आप context.startService() और context.bindService() मेथड्स से स्टार्ट कर सकते है।            जब service component क्रिएट होता है तो android syst...

Android Fragments

Android Fragments Introduction to android fragments in Hindi Android fragments life cycle in Hindi Types of android fragments in Hindi Creating android fragment in Hindi Introduction to Android Fragments एक fragment किसी activity के अंदर एक separate UI (user interface) होता है। Fragments की खुद की life cycle और input events होते है। आप एक fragment को कई activities में use कर सकते है। जब आपकी activity running state में हो तब भी आप fragments को add और remove कर सकते है। Fragments को आप sub activity भी कह सकते है।   Android fragments को android के Honeycomb version में introduce किया गया था।  Android fragments से पहले आप user को एक बार में एक activity ही show कर सकते थे इसलिए आप स्क्रीन को अलग अलग parts में divide नहीं कर सकते थे। Fragments के आने से application design और भी ज्यादा flexible हो गयी क्योंकि आप यूजर को एक साथ एक से ज्यादा interface शो कर सकते है और उन्हें separately manage भी कर सकते है। अब आपके पास activity तो एक ही रहेगी लेकिन आप इसमें ब...

Android Development Tools

Android Development Tools  Android SDK in Hindi  Android Debug bridge in Hindi Android gradle in Hindi Android studio in Hindi Android run time and delvik in Hindi  Android SDK  Android SDK (Software Development Kit) -  Android SDK  में वो सभी टूल्स होते है जिनकी आपको एंड्राइड एप्लीकेशन क्रिएट करने में, कम्पाइल करने में और एप्लीकेशन को पैकेज करने के लिए जरुरत पड़ेगी।  Android SDK में आपको सोर्स कोड के साथ सैंपल प्रोजेक्ट्स, डेवलपमेंट टूल्स, एक इमुलेटर और एप्लीकेशन डेवेलप करने के लिए रिक्वायर्ड लाइब्रेरीज मिलती है। सभी एप्लीकेशन java में डेवेलप की जाती है और डेलविक वर्चुअल मशीन पर रन की जाती है। Android debug bridge  ADB  (Android Debug Bridge  ) - ADB android SDK का एक कमांड लाइन  टूल है जिसकी मदद से आप अपनी एप्लीकेशन को वर्चुअल डिवाइस या किसी रियल डिवाइस पर रन करवा सकते है और डिबग कर सकते है। ये एक क्लाइंट सर्वर प्रोग्राम होता है जिसमे एक क्लाइंट होता है, एक सर्वर...