2013-11-22 86 views
1

我正在尋找小時,但沒有找到解決方案。我有一個佈局爲如下:Android視圖.setTranslationY()視圖裁剪

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/remote_parent" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    tools:context=".TevidiHome$RemoteFragment" > 

    <RelativeLayout 
     android:id="@+id/remote_extra" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     tools:context=".TevidiHome$FragmentRemote" > 

     <TextView 
      android:id="@+id/remote_text_active" 
      android:layout_width="30dp" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:layout_marginBottom="30dp" 
      android:background="@drawable/border" 
      android:textColor="@android:color/holo_orange_dark" 
      android:textSize="30sp" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/remote_text_waiting" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="35dp" 
      android:layout_marginRight="5dp" 
      android:layout_toLeftOf="@id/remote_text_active" 
      android:textSize="20sp" /> 

     <EditText 
      android:id="@+id/remote_text_store" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:layout_marginTop="-500dp" 
      android:layout_toLeftOf="@id/remote_text_waiting" 
      android:descendantFocusability="beforeDescendants" 
      android:focusable="true" 
      android:imeOptions="actionNone" 
      android:inputType="text|textNoSuggestions" /> 

     <ImageView 
      android:id="@+id/remote_logo" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/remote_text_active" 
      android:layout_centerHorizontal="true" 
      android:contentDescription="@string/remote_logo_desc" 
      android:src="@drawable/number_block" /> 

     <ImageView 
      android:id="@+id/remote_border" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/remote_logo" 
      android:layout_centerHorizontal="true" 
      android:layout_marginTop="2dp" 
      android:contentDescription="@string/remote_border_desc" 
      android:src="@drawable/remote_border" /> 
    </RelativeLayout> 

    <RelativeLayout 
     android:id="@+id/remote_main" 
     android:layout_width="match_parent" 
     android:layout_height="fill_parent" 
     android:layout_marginTop="3dp" 
     android:layout_below="@id/remote_extra" 
     > 

     <ImageView 
      android:id="@+id/tevidi_logo" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:contentDescription="@string/remote_tevidi_logo_desc" 
      android:src="@drawable/tevidi_logo" /> 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentTop="true" 
      android:layout_marginRight="10dp" > 

      <ImageButton 
       android:id="@+id/remote_sos" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="20dp" 
       android:layout_marginRight="10dp" 
       android:background="@drawable/button_sel" 
       android:contentDescription="@string/remote_sos_desc" 
       android:src="@drawable/sos_off" /> 

      <ImageButton 
       android:id="@+id/remote_alarm" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="@drawable/button_sel" 
       android:contentDescription="@string/remote_alarm_desc" 
       android:src="@drawable/alarm_off" /> 
     </LinearLayout> 

     <!-- Arrows --> 

     <ImageButton 
      android:id="@+id/remote_top" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:lenter code hereayout_above="@+id/remote_ok" 
      android:layout_centerHorizontal="true" 
      android:background="@drawable/button_sel" 
      android:contentDescription="@string/remote_top_desc" 
      android:src="@drawable/remote_top" /> 

     <ImageButton 
      android:id="@+id/remote_left" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:layout_toLeftOf="@+id/remote_ok" 
      android:background="@drawable/button_sel" 
      android:contentDescription="@string/remote_left_desc" 
      android:src="@drawable/remote_left" /> 

     <ImageButton 
      android:id="@+id/remote_ok" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:background="@drawable/button_sel" 
      android:contentDescription="@string/remote_ok_desc" 
      android:src="@drawable/remote_ok" /> 

     <ImageButton 
      android:id="@+id/remote_right" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:layout_toRightOf="@+id/remote_ok" 
      android:background="@drawable/button_sel" 
      android:contentDescription="@string/remote_right_desc" 
      android:src="@drawable/remote_right" /> 

     <ImageButton 
      android:id="@+id/remote_down" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/remote_ok" 
      android:layout_centerHorizontal="true" 
      android:background="@drawable/button_sel" 
      android:contentDescription="@string/remote_down_desc" 
      android:src="@drawable/remote_down" /> 

     <!-- Bottom Buttons --> 

     <ImageButton 
      android:id="@+id/remote_back" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentLeft="true" 
      android:layout_marginLeft="10dp" 
      android:layout_marginTop="30dp" 
      android:background="@drawable/button_sel" 
      android:contentDescription="@string/remote_back_desc" 
      android:adjustViewBounds="true" 
      android:src="@drawable/remote_back" /> 

     <ImageButton 
      android:id="@+id/remote_menu" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentRight="true" 
      android:layout_marginRight="10dp" 
      android:layout_marginTop="30dp" 
      android:background="@drawable/button_sel" 
      android:contentDescription="@string/remote_menu_desc" 
      android:src="@drawable/remote_menu" /> 

    </RelativeLayout> 

</RelativeLayout> 

的remote_extra佈局由View.setTranslationY(-170),通過拖動手勢可以swipped向下拉出屏幕。這很好。 問題是:由於TranslationY,remote_main佈局不在屏幕的底部,而是170pixels以上。我沒有設法讓它回到底部。當我以編程方式使remote_main佈局更高時,按鈕被切斷。

無法添加屏幕截圖。因此,一個在這裏:https://www.dropbox.com/s/52erx4jatzsqz80/Screenshot_2013-11-22-13-46-17.png

它應該就像這裏。底部的空空間應該充滿上面的觀點:https://www.dropbox.com/s/xw8km88lmz9be4q/Screenshot_good.png

我嘗試以下沒有什麼幫助:

LayoutParams params = rootView.findViewById(R.id.remote_parent).getLayoutParams(); 
       rootView.findViewById(R.id.remote_parent).setTranslationY(UP_PADDING); 

LayoutParams params2 = rootView.findViewById(R.id.remote_main).getLayoutParams(); 
params2.height = 1400; 

((ViewGroup) rootView.findViewById(R.id.remote_parent)).setClipChildren(false); 
((ViewGroup) rootView.findViewById(R.id.remote_main)).setClipChildren(false); 
rootView.requestLayout(); 
rootView.invalidate(); 

是否有人有辦法解決嗎?

+0

請張貼一些屏幕截圖 – Tejas

+0

添加了一個屏幕截圖 – Manu

+0

它可以幫助提供你想要的畫面是什麼樣子的繪圖,所以它更清楚。 –

回答

0

好吧,我設法移動到按鈕,但他們沒有更多的可點擊;-(

所以我切換到SlidingDrawer。過了一會兒,我發現,它已被棄用,但無論如何,它正是我需要......

0

我有類似的問題 - 翻譯的看法是比屏幕高(WRAP_CONTENT有更多的像素比Y尺寸屏幕),當我翻譯的看法時,底部並沒有呈現在所有

。我的解決方案:使用ScrollView作爲slinged視圖,但如果它到達屏幕頂部,請撥打scrollTo()而不是translateY()

private void customScroll(int y) 
{ 
    setTranslationY(Math.max(y, 0)); 
    scrollTo(0,Math.max(0, -y)); 
}