2015-01-02 52 views
2

我注意到,像google maps和lyft這樣的應用程序具有當用戶開始在文本字段中輸入地址時,文本字段佔據整個屏幕(開始新的活動),特別關注投入。當用戶從列表視圖中選擇一些東西時,他們會帶着所有其他信息回到屏幕上當用戶在編輯文本中輸入值時的Android開始活動

我只是好奇如何能夠實現這樣的事情。 他們正在使用不同的活動嗎?

enter image description here

,我的工作在App有類似的功能,但我想我不知道如何讓我的文本框,以覆蓋整個屏幕(或者啓動不同的活動),當用戶開始輸入。

我只是在尋找一個指針或例子。不幸的是,因爲我不知道我所看到的確切名稱,所以它在文檔中搜索它有點困難。任何指針將不勝感激!

PS:我知道這種方法的,但不是我所期待的

<activity android:name=".MyActivity" android:windowSoftInputMode=""/>

+0

我認爲這是一個很好的地方使用片段,而不是開始一個新的活動。另外,看看這是否有幫助:http://developer.android.com/guide/topics/search/search-dialog.html – Populus

+0

你甚至可以全屏使用對話框 –

回答

0

,我結束了做一個簡單的方法是開始活動的結果,一旦文本框被激活,並設置該值一次新的完成

0

我實際上做的是:我會創造它作爲一個「簡單」的觀點。不是片段,不是活動。

  • 我將通過創建一個佈局,將代表你的TextView的 「擴展」版本開始(我將區分之間擴大倒塌的看法狀態;膨脹的狀態時,它填補了整個屏幕)。
  • 我會將其寬度和高度設置爲match_parent,我會將 放置在活動(或片段或其他)中。例如用align_parentTop來固定它。
  • 主活動的佈局設置clipChildrenfalse
  • 這裏面ActivityonCreate(或其他一些
    排序容器類似的地方),我想補充更多的東西少是這樣的:

代碼:

mExpandableTextView = (RelativeLayout)findViewById(R.id.expandable_text_view_layout); 
    //layout representing the expandable textview (defined in expanded state) 

mExpandableTextView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { 
    @Override 
    public void onGlobalLayout() { 
     int width = mExpandableTextView.getWidth(); 
     int height = mExpandableTextView.getHeight(); 
     if (width > 0 && height > 0) { 
      mExpandableTextView.getViewTreeObserver().removeOnGlobalLayoutListener(this); 

      // setting the height and width of the view to fixed values (instead of match_parent) 
      // this problably is not really necessary but I will write it just to be sure it works as intended 
      RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)mExpandableTextView.getLayoutParams(); 
      params.height = height; 
      params.width = width; 
      mExpandableTextView.setLayoutParams(params); 

      mMaxTranslationY = height - mCollapsedHeight; 
       //mCollapsedHeight is the height of the view in collapsed state 
       //provide it in most convenient way for you 

      mExpandableTextView.setTranslationY(mMaxTranslationY); 
       //setting it to the collapsed state when activity is being displayed for the first time 
     } 
    } 
}); 

(請記住,使用removeGlobalOnLayoutListener()如果你的應用是設備< API16

  • 然後,我會在我們處於摺疊狀態時,視圖(佈局)的唯一可見部分檢測點擊,我會用下面的代碼來展開或摺疊:

崩潰:

mExpandableTextView.animate().translationY(mMaxTranslationY); //to collapse with animation 

擴大:

mExpandableTextView.animate().translationY(0); //to expand with animation 
相關問題