के लिए हेडर या फ़ूटर बटन बार कैसे बना सकता हूं Google मानचित्र, फेसबुक, फोरस्क्वेयर आदि जैसे कई लोकप्रिय ऐप्स में उनकी अधिकांश गतिविधियों पर हेडर और/या फ़ूटर बार हैं। इन शीर्षलेखों में अक्सर बहुत उपयोगी बटन शामिल होते हैं, और मैं अपने ऐप के लिए एक बनाना चाहता हूं। क्या किसी को पता है कि वे कैसे किए जाते हैं? मैं अभी तक कुछ भी नहीं ढूंढ पाया है। http://www.flickr.com/photos/calebgomer/6262815430 http://www.flickr.com/photos/calebgomer/6262815458मैं अपने एंड्रॉइड एप्लिकेशन
उत्तर
आप अपने header-footer xml
बनाने के लिए और अपने activity
में से किसी के लिए इसका इस्तेमाल कर सकते हैं इस तरह से उपयोग करने पर आप सिर्फ शीर्षक में नियंत्रण के लिए लिखने कोड की जरूरत हेडरफूटर.जावा में -फुटर और इसे अपने प्रोजेक्ट तक पहुंच सकते हैं।
अपने HederFooter.xml
<?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" android:weightSum="10"
android:id="@+id/commonlayout" android:background="#FFFFFF">
<LinearLayout android:id="@+id/llheader"
android:layout_width="fill_parent" android:layout_height="0dp"
android:background="@drawable/bar" android:layout_weight="1">
<RelativeLayout android:id="@+id/relativeLayout1"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_gravity="center">
<Button
android:id="@+id/Button_HeaderFooterSubscribe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="2dp"
android:layout_centerVertical="true"
android:background="@drawable/subscribe"
/>
<Button
android:id="@+id/Button_logout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="2dp"
android:layout_centerVertical="true"
android:background="@drawable/logout"
/>
<Button
android:id="@+id/Button_playlist"
android:layout_marginLeft="2dp"
android:layout_width="wrap_content"
android:layout_centerVertical="true"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="@drawable/tempadd"
/>
</RelativeLayout>
</LinearLayout>
<LinearLayout android:id="@+id/lldata"
android:layout_weight="8" android:layout_width="fill_parent"
android:layout_height="0dp" android:background="#FFFFFF">
</LinearLayout>
<LinearLayout android:id="@+id/llfooter"
android:layout_weight="1" android:layout_width="fill_parent"
android:orientation="horizontal" android:layout_height="0dp"
android:visibility="visible" android:background="@drawable/fbg"
android:weightSum="5.0" android:gravity="center"
android:layout_margin="0dp">
<Button android:id="@+id/home" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:layout_weight="1"
android:background="@drawable/home" android:textColor="#FFFFFF"
android:padding="10px"></Button>
<Button android:id="@+id/issue" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:layout_weight="1"
android:background="@drawable/issue" android:textColor="#FFFFFF"
android:padding="10px"></Button>
<Button android:id="@+id/browse" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:layout_weight="1"
android:background="@drawable/browse" android:textColor="#FFFFFF"
android:padding="10px"></Button>
<Button android:id="@+id/search" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:layout_weight="1"
android:background="@drawable/search" android:textColor="#FFFFFF"
android:padding="10px"></Button>
<Button android:layout_height="wrap_content" android:id="@+id/favorite"
android:background="@drawable/favorite" android:layout_width="wrap_content"
android:layout_weight="1"
android:textColor="#FFFFFF" android:padding="10px"></Button>
</LinearLayout>
</LinearLayout>
बिल्ड फिर एक HeaderFooter.java गतिविधि
public class HeaderFooter extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.headerfooter);
}
}
बनाएं अब आपके सभी अन्य गतिविधियों के लिए गतिविधि के ऊपर का विस्तार करने और अपने विशेष दृश्य बढ़ में headerfooter.xml का मध्य लेआउट
public class Home extends HeaderFooter
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
ViewGroup vg = (ViewGroup) findViewById(R.id.lldata);
ViewGroup.inflate(Home.this, R.layout.home, vg);
}
}
बस एक एक्सएमएल बनाने के रूप में आप की जरूरत है:
यहाँ मैं क्या मतलब है की कुछ तस्वीरें हैं।
इन XML को अपने अन्य स्क्रीन एक्सएमएल में टैग का उपयोग करके अपनी अन्य स्क्रीन पर जोड़ें।
आप के रूप में आप प्रत्येक गतिविधि में की जरूरत है बटन पर क्लिक संभाल कर सकते हैं।
उम्मीद है कि इससे मदद मिलती है।
मैंने पहले एंड्रॉइड पर काम किया है। मेरे पास काम करने वाले ऐप्स हैं, मैं बस उनके जीयूआई को बेहतर दिखाना चाहता हूं। मैं उन नमूनों को देखूंगा और देख सकता हूं कि मैं क्या कर सकता हूं। धन्यवाद! –
@ विनी इस लिंक को तोड़ने वाला लिंक न दें। कृपया अपना लिंक अपडेट करें। – BBdev
हेडर, पाद लेख और शरीर के साथ डिज़ाइन एक्सएमएल लेआउट। आपको हर बार मुख्य गतिविधि का विस्तार करना होगा, आपको वांछित लेआउट को बढ़ाकर शरीर को बदलना होगा।
मुझे लगता है कि आप उन लेआउट में जो तत्व पसंद कर रहे हैं वह यह तथ्य है कि वे प्रदर्शन के निचले भाग के लिए फ़्रेमलेआउट का उपयोग कर रहे हैं।
वे शायद कुछ इस तरह कर रहे हैं:
<LinearLayout android:orientation="vertical
.../>
<head layout element>
<FrameLayout element>
<footer layout element>
</LinearLayout>
क्या लीनरलाइट फ़ूटर का उपयोग करने और फ़ूटर के लिए फ़्रेमलाउट का उपयोग करने में कोई अंतर है? –
यह फ़ूटर नहीं है जो फ़्रेमेलआउट है। यह सामग्री फलक है जो फ्रेम लेआउट है। मैंने अपना उत्तर अधिक विशिष्ट होने के लिए संपादित किया है। –
मुझे लगता है कि आपका क्या मतलब है। मैंने लाइनरलाउट से "फ्रेम" को फ्रेमलेआउट में बदल दिया लेकिन मुझे दोनों के बीच कोई अंतर नहीं दिखाई दिया। क्या इस स्थिति में फ्रेमलेआउट का उपयोग करने के लिए व्यावहारिक फायदे हैं? –
यह दृष्टिकोण बहुत अच्छा काम करता है, धन्यवाद! (एकमात्र समस्या यह है कि पाद लेख के बीच और स्क्रीन के निचले हिस्से में बहुत छोटा अंतर होता है) –
@CalebGomer मैंने xml का उपयोग किया है और यह समस्या हल हो जाएगी .. अगर मुझे – MKJParekh
यह तय किया गया है तो मुझे बताएं! आपकी सहायता के लिए एक बार फिर से धन्यवाद। –