2016-03-22 95 views
0
<?xml version="1.0" encoding="utf-8"?> 
<HorizontalScrollView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:fillViewport="true" 
    android:id="@+id/resend_scroll"> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="110dp" 
     android:orientation="horizontal"> 

     <include layout="@layout/partial_resend_layout" 
      android:layout_height="110dp" 
      android:layout_width="124dp" 
      android:id="@+id/resend_invite" 
      /> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="110dp" 
      android:orientation="vertical"> 

     <TextView 
      android:id="@+id/text_invitee_name" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@android:color/transparent" 
      android:layout_marginTop="24dp" 
      android:layout_marginLeft="30dp" 
      android:layout_marginStart="30dp" 
      android:fontFamily="@string/regular_roboto" 
      android:textColor="@color/white" 
      android:textSize="22sp"/> 

     <TextView 
      android:id="@+id/text_invitee_contact_number" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@android:color/transparent" 
      android:layout_marginTop="18dp" 
      android:layout_marginLeft="30dp" 
      android:layout_marginStart="30dp" 
      android:fontFamily="@string/regular_roboto" 
      android:textColor="@color/white" 
      android:textSize="22sp"/> 
     </LinearLayout> 

    </LinearLayout> 
</HorizontalScrollView> 

這是我的xml文件,但linearlayout match_parent寬度不起作用既包含和佈局在屏幕中可見!我正在向左滾動項目,所以左側的項目不應該是可見的!我不知道該怎麼做.. 這個xml文件是recyclerview的項目。如果我將寬度設置爲某個值,它可以正常工作。但是,當屏幕尺寸改變寬度尺寸的變化,因此它顯示了包括部分現在我做這個使用水平滾動視圖從左向右滾動

DisplayMetrics metrics = new DisplayMetrics(); 
     WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); 
     wm.getDefaultDisplay().getMetrics(metrics); 
     LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(metrics.widthPixels, holder.mWidthTextView.getHeight()); 
     holder.mWidthTextView.setLayoutParams(lp); 
     holder.mResendScroll.postDelayed(new Runnable() { 
      public void run() { 
       holder.mResendScroll.fullScroll(HorizontalScrollView.FOCUS_RIGHT); 
      } 
     }, 10L); 

它的工作原理,但我不認爲這是因爲這就是所謂的onBindViewHolder每一次的正確方法。

+0

簡單。在創建Horizo​​ntalScrollView的對象之後,在創建活動/片段時執行此操作。 'resend_scroll.fullScroll(Horizo​​ntalScrollView.FOCUS_RIGHT);' – MKJParekh

+0

我會編輯我的問題 – Lol

+0

Plz,請清楚您所要求的內容並完整呈現您的代碼和問題。 – MKJParekh

回答

0

你可以嘗試第一個LinearLayout寬度「match_parent」。

從代碼

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="110dp" 
    android:orientation="horizontal">` 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="110dp" 
    android:orientation="horizontal">` 
+0

謝謝,我需要從右向左滑動因此第一個線性佈局應該是不可見的。 – Lol

+0

抱歉不明白你需要什麼。請清除,然後可能是我可以幫助 – Prosanto