2012-11-25 12 views
10

के बाद अब एक स्लाइडिंग ड्रावर को कार्यान्वित करने के लिए वैकल्पिक तरीका है, मेरे ऐप में मेरे पास छवि बटन के साथ एक स्लाइडिंग ड्रॉवर है और जब क्लिक किया गया है तो यह छवि विवरण और जानकारी प्रदर्शित करता है। तो मूल रूप से मैं केवल इसके लिए एक एक्सएमएल फ़ाइल और एक जावा फ़ाइल का उपयोग कर रहा हूं। (लेकिन मैंने देखा है कि प्रदर्शित करने के लिए और अधिक छविबूटन और mages जोड़ने में लोड होने में कुछ समय लगता है)। और अब जब से एपीआई 17 स्लाइडिंग ड्रॉवर को छोड़कर ऐप के भविष्य के डाउनलोड के लिए मुझे थोड़ा चिंतित करता है। अब मेरा सवाल यह है कि स्लाइडिंग ड्रॉवर या स्पिनर का उपयोग किये बिना इसे हासिल करने का एक वैकल्पिक तरीका है। मैं वास्तव में प्रत्येक छवि के लिए एक एक्सएमएल और जावा फ़ाइल नहीं बनाना चाहता (मैं 100+ एक्सएमएल और जावा के साथ समाप्त हो जाऊंगा) यहां मेरा कोड है जो मेरे पास है।एपिआई 17

एक्सएमएल:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<ScrollView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 

<ImageView 
    android:id="@+id/iM1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:scaleType="fitStart" 
    android:adjustViewBounds="true"/> 

</RelativeLayout> 
</ScrollView> 

<SlidingDrawer 
    android:id="@+id/sD1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    android:content="@+id/content" 
    android:handle="@+id/handle"> 

    <Button 
     android:id="@+id/handle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/icon_1" /> 

    <RelativeLayout 
     android:id="@+id/content" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@drawable/icon_background1"> 

     <ScrollView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" > 

      <RelativeLayout 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" > 

       <Button 
        android:id="@+id/asample" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:background="@drawable/imageicon1"/> 
        ..... 

और जावा:

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    requestWindowFeature(Window.FEATURE_NO_TITLE); 
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); 
    setContentView(R.layout.campsites); 
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 
    final SlidingDrawer slider = (SlidingDrawer) findViewById(R.id.sD1); 
    final ImageView imageView = (ImageView) findViewById(R.id.iM1); 
    slider.animateOpen(); 

    Button next = (Button) findViewById(R.id.asample); 
    Button next1 = (Button) findViewById(R.id.bsample); 
    .......... 

    next.setOnClickListener(new View.OnClickListener() { 

     public void onClick(View view) { 
      imageView.setImageDrawable(getResources().getDrawable(R.drawable.asample)); 
      slider.animateClose(); 
     } 
    }); 
    next1.setOnClickListener(new View.OnClickListener() { 

     public void onClick(View view) { 
      imageView.setImageDrawable(getResources().getDrawable(R.drawable.bsample)); 
      slider.animateClose(); 
     } 
    }); 
    ............ 

किसी को भी मदद या क्या करना है पर एक सुझाव है सकते हैं?

उत्तर

0

मैं सोचता This एक अच्छा विकल्प
AFAIK यह SlidingDrawer उपयोग नहीं करता है और आप दराज

3

यह बाईं, सही से एक SlidingDrawer है की दिशा को संशोधित कर सकते है? यदि ऐसा है, तो आप DrawerLayout देख सकते हैं।

इस Android समर्थन लाइब्रेरी का हिस्सा है और आप के बजाय काफी बस इस के साथ अपने एक्सएमएल की जगह और पीछे की ओर API4

कि पृष्ठ से करने के लिए संगत होना में सक्षम होना चाहिए, वहाँ एक उदाहरण है।

  • मुख्य सामग्री दृश्य (FrameLayout ऊपर) DrawerLayout क्योंकि में पहला बच्चा होना चाहिए:

    <android.support.v4.widget.DrawerLayout 
        xmlns:android="http://schemas.android.com/apk/res/android" 
        android:id="@+id/drawer_layout" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent"> 
        <!-- The main content view --> 
        <FrameLayout 
         android:id="@+id/content_frame" 
         android:layout_width="match_parent" 
         android:layout_height="match_parent" /> 
        <!-- The navigation drawer --> 
        <ListView android:id="@+id/left_drawer" 
         android:layout_width="240dp" 
         android:layout_height="match_parent" 
         android:layout_gravity="start" 
         android:choiceMode="singleChoice" 
         android:divider="@android:color/transparent" 
         android:dividerHeight="0dp" 
         android:background="#111"/> 
    </android.support.v4.widget.DrawerLayout> 
    

    कि पेज

    इस लेआउट से कुछ नोट कुछ महत्वपूर्ण लेआउट विशेषताओं को दर्शाता है एक्सएमएल ऑर्डर का अर्थ है जेड ऑर्डरिंग और दराज सामग्री के शीर्ष पर होना चाहिए। मुख्य सामग्री दृश्य पेरेंट दृश्य की चौड़ाई और ऊंचाई से मेल खाने के लिए सेट किया गया है, क्योंकि नेविगेशन ड्रॉवर छुपाए जाने पर यह संपूर्ण UI का प्रतिनिधित्व करता है।

  • दराज दृश्य (सूची दृश्य) को एंड्रॉइड के साथ क्षैतिज गुरुत्वाकर्षण निर्दिष्ट करना होगा: layout_gravity विशेषता। दाएं से बाएं (आरटीएल) भाषाओं का समर्थन करने के लिए, "बाएं" के बजाय "प्रारंभ" के साथ मान निर्दिष्ट करें (इसलिए लेआउट आरटीएल होने पर दराज दाईं ओर दिखाई देता है)।
  • दराज दृश्य डीपी इकाइयों में इसकी चौड़ाई निर्दिष्ट करता है और ऊंचाई अभिभावक दृश्य से मेल खाती है। दराज की चौड़ाई 320 डीपी से अधिक नहीं होनी चाहिए ताकि उपयोगकर्ता हमेशा मुख्य सामग्री का एक हिस्सा देख सके।

अधिकतर अंतर यह है कि DrawerLayout शीर्ष स्तर है है और आप इसे भीतर अपने एक्सएमएल डाल दिया। इस तरह तो कुछ (पूरी तरह अपरीक्षित):

<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <!-- your content surrounded by a layout to signify that it's actually content --> 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <ScrollView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"> 
      <RelativeLayout 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content"> 

       <ImageView 
        android:id="@+id/iM1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:scaleType="fitStart" 
        android:adjustViewBounds="true"/> 

      </RelativeLayout> 
     </ScrollView> 
    </RelativeLayout> 
    <!-- your sliding menu in its own layout --> 
    <LinearLayout 
     android:layout_gravity="start" 
     android:layout_width="240dp" 
     android:layout_height="wrap_content"> 
     <Button 
      android:id="@+id/handle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@drawable/icon_1" /> 

     <RelativeLayout 
      android:id="@+id/content" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@drawable/icon_background1"> 

      <ScrollView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" > 

       <RelativeLayout 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" > 

        <Button 
         android:id="@+id/asample" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:background="@drawable/imageicon1"/> 
         ..... 
    </LinearLayout> 
</android.support.v4.widget.DrawerLayout> 
1

मैं नहीं बल्कि एक साधारण रपट मेनू सुझाव है, कि मैं अपने आप बनाया।

अवधारणा मैं

स्लाइडर बटन और सामग्री पैनल

इस्तेमाल किया शुरू में स्लाइडर बटन बाईं ओर है (मेरे उदाहरण में), जब आप उस पर क्लिक करें, यह बदलाव और सामग्री फलक दिखाई दे जाता है

मैं कैसे achieived इस

मैं मार्जिन छोड़ दिया के साथ खेला जाता है, इसलिए जब आप स्लाइडर बटन Conte प्रेस एनटी फलक (प्रारंभ में छिपा हुआ) स्क्रीन_विड्थ/3 के रूप में चौड़ा हो जाता है, और जब आप इसे फिर से दबाते हैं तो यह छिपाता है ..

मेरा कोड है।

public class MainActivity extends Activity { 
    boolean toggle_open=false; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 




    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.activity_main, menu); 
     return true; 
    } 

    public void open(View v){ 
     switch (v.getId()) { 
     case R.id.imageButton1: 
      if(!toggle_open){ 
      RelativeLayout header=(RelativeLayout)findViewById(R.id.header); 
      Display size=getWindow().getWindowManager().getDefaultDisplay(); 
      int widthby2=size.getWidth()/3; 
      RelativeLayout.LayoutParams lp=new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT); 
      lp.setMargins(size.getWidth()/2, 0, 0, 0); 
      header.setLayoutParams(lp); 

      RelativeLayout slider=(RelativeLayout)findViewById(R.id.panel); 
      slider.setLayoutParams(new RelativeLayout.LayoutParams((size.getWidth()/2),size.getHeight())); 
      slider.setVisibility(View.VISIBLE); 

      toggle_open=true; 
      } 
      else{ 
       RelativeLayout header=(RelativeLayout)findViewById(R.id.header); 
       RelativeLayout.LayoutParams lp=new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT); 
       lp.setMargins(0, 0, 0, 0); 
       header.setLayoutParams(lp); 

       RelativeLayout slider=(RelativeLayout)findViewById(R.id.panel); 
       slider.setVisibility(View.GONE); 
       toggle_open=false; 

      } 
      break; 

     default: 
      break; 
     } 
    } 



} 

// एक्सएमएल कोड

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".MainActivity" > 

    <RelativeLayout 
     android:id="@+id/header" 
     android:background="@android:color/black" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:padding="20dp" > 

     <ImageButton 
      android:id="@+id/imageButton1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentTop="true" 
      android:background="@android:color/black" 
      android:onClick="open" 
      android:src="@android:drawable/ic_dialog_dialer" /> 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignBottom="@+id/imageButton1" 
      android:layout_toRightOf="@+id/imageButton1" 
      android:text="Admin Panel" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:textColor="@android:color/white" /> 

    </RelativeLayout> 

    <RelativeLayout 
     android:id="@+id/panel" 
     android:visibility="gone" 
     android:layout_toLeftOf="@+id/header" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:background="@android:color/darker_gray" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" > 

     <fragment class="com.example.avanse.FragmentLayout$TitlesFragment" 
      android:id="@+id/titles" 
      android:layout_width="match_parent" android:layout_height="match_parent"/> 

    </RelativeLayout> 

</RelativeLayout> 
0

सादा एंड्रॉयड आप DrawerLayout उपयोग कर सकते हैं। लेकिन मैं SlidingMenu lib की सलाह देता हूं कि उपयोगकर्ता और प्रोग्रामर के लिए बेहतर उपयोगिता क्या है।

+0

ड्रॉवरलाइट पुराने एंड्रॉइड संस्करणों के साथ भी काम करता है यह v4 समर्थन पुस्तकालय में है। – NasaGeek

+0

आप सही हैं - मैं इसे सही करने के लिए अपना उत्तर संपादित करूंगा –

1

ऐप उमेनो के लोगों से स्लाइडिंगअपपैनल अभी सबसे अच्छा तरीका प्रतीत होता है। vertical DrawerLayout or SlidingPaneLayout :: डी

संपादित करें: https://github.com/umano/AndroidSlidingUpPanel

मैं इस अन्य SOF पोस्ट में इसके बारे में जानकारी मिली: आप इसे में पा सकते हैं https://github.com/6wunderkinder/android-sliding-layer-lib (यूट्यूब वीडियो में काम करने के लिए लगता है: यह एक भी बहुत आशाजनक दिखता है दाएं से बाएं और बाएं से दाएं, लेकिन यदि आप वास्तविक डेमो ऐप डाउनलोड करते हैं, तो आप देखेंगे कि नीचे से ऊपर और ऊपर से नीचे तक जाना भी संभव है)

संबंधित मुद्दे