2016-08-03 2 views
2

У меня есть RecyclerViewScroll TextView внутри RecyclerView

<android.support.v7.widget.RecyclerView 
      android:id="@+id/activityRecicler" 
      android:layout_width="match_parent" 
      android:scrollbars="vertical" 
      android:layout_height="wrap_content" 
      app:stackFromEnd="true" 
      /> 

И у меня есть макет строки:

<LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     > 
    <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/description"/> 

    <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/solutions"/> 

    </LinearLayout> 

И работа контента обертки, но моя проблема заключается в том, что TextView с описанием ид Это может быть очень долго и так, у меня был бы Scroll для этого TextView. Как я мог это сделать?

+0

Оберните его внутри scrollview? –

+0

Не уверен, что я понимаю проблему. Прокрутка ресайклера и отображает весь элемент, не так ли? Итак, чего вы пытаетесь достичь? TextViews являются многострочными, поэтому простой прокруткой Recycler вы увидите весь контент. – mhenryk

+0

Можете ли вы опубликовать снимок экрана экрана, который вы сейчас получаете. Предпочтительным является SS с длинным текстом. –

ответ

7

Изменение макета XML для:

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

    <ScrollView 
     android:id="@+id/childScroll" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <TextView 
      android:id="@+id/description" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 
    </ScrollView> 

    <TextView 
     android:id="@+id/solutions" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 

</LinearLayout> 

И тогда в вашей деятельности:

activityRecicler.setOnTouchListener(new View.OnTouchListener() { 

    public boolean onTouch(View v, MotionEvent event) { 
     findViewById(R.id.childScroll).getParent().requestDisallowInterceptTouchEvent(false); 
     return false; 
    } 
}); 
childScroll.setOnTouchListener(new View.OnTouchListener() { 

    public boolean onTouch(View v, MotionEvent event) { 
     // Disallow the touch request for parent scroll on touch of child view 
     v.getParent().requestDisallowInterceptTouchEvent(true); 
     return false; 
    } 
}); 
+0

привет, спасибо, activityRecicler - RecyclerView) findViewById (R.id.activityRecicler); Но Chldscroll? – LorenzoBerti

+0

в xml файле выше. –

+0

да, но как я могу получить доступ к активности в rowLayout в действии? – LorenzoBerti

2

Попробуйте под кодом, указанным в вашем текстовом идентификаторе.

scrollable = (TextView)findViewById(R.id.textView1); 
//Enabling scrolling on TextView. 
scrollable.setMovementMethod(new ScrollingMovementMethod()); 

добавить в TextViewмакете

android:scrollbars="vertical" 
0

либо вы можете обернуть его в scrollview как этот

<ScrollView 
    android:layout_height="100px" 
    android:layout_width="fill_parent"> 
    <TextView 
     android:id="@+id/text_view" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:text="long_text"/> 
</ScrollView> 

или

добавить эти два атрибута YOUT textview

android:maxLines="5" 
android:scrollbars="vertical" 

и добавьте ниже строки в код

textview.setMovementMethod(new ScrollingMovementMethod()); 

надеюсь, что это помогает :)

+0

Привет, спасибо, но я не могу прокрутить :(Я опубликовал фотографию и код. – LorenzoBerti

+0

Редактирование: Я заметил, что могу прокручивать по горизонтали:/i comfused ... – LorenzoBerti

+0

Измените свой 'textview'' width' to 'fill_parent' вместо' wrap_content' –

0

rowlayout.xml

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    > 
<TextView 
     android:id="@+id/description" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:ellipsize="marquee" 
     android:fadingEdge="horizontal" 
     android:lines="1" 
     android:marqueeRepeatLimit="marquee_forever" 
     android:scrollHorizontally="true" 
     android:singleLine="true" 
     android:textColor="#ff4500" /> 
<TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/solutions"/> 
</LenearLayout> 

и активности

descrptionTextview.setSelected(true); 
2

Я новичок на Android, и поэтому я не знаю, если мое решение, это хорошо. я поставил в Layout Row как это было предложено @Payal

<ScrollView 
     android:id="@+id/childScroll" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <TextView 
      android:id="@+id/solutions" 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:text="long_text" 
      android:maxLines="5" 
      android:scrollbars="vertical"/> 
    </ScrollView> 

И в Мой ViewHolder

public ViewHolder(View itemView) { 
      super(itemView); 
      solutions = (TextView) itemView.findViewById(R.id.solutions); 
      description = (TextView) itemView.findViewById(R.id.description); 
      scrollable = (ScrollView) itemView.findViewById(R.id.childScroll); 


      solutions.setOnTouchListener(new View.OnTouchListener() { 

       public boolean onTouch(View v, MotionEvent event) { 
        // Disallow the touch request for parent scroll on touch of child view 
        v.getParent().requestDisallowInterceptTouchEvent(true); 
        return false; 
       } 
      }); 

//Enabling scrolling on TextView. 

      solutions.setMovementMethod(new ScrollingMovementMethod()); 
     } 

И это работа. можно прокручивать TextView в моей RecyclerView

+0

Если какой-то ответ помог вам, что вы должны сделать, это ответить на этот вопрос и пометить его как правильное. См. Http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – Sufian

+0

И, пожалуйста, не оставляйте комментарии в качестве ответа. – Sufian

+0

Hello Surfian, извините за комментарий. этот ответ мой, и я могу принять свой ответ в ближайшие 21 час. – LorenzoBerti

0

Сделать новый класс

public class AutoScrollingTextView extends TextView { 

    public AutoScrollingTextView(Context context, AttributeSet attrs, int defStyle) { 
     super(context, attrs, defStyle); 
    } 

    public AutoScrollingTextView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 

    public AutoScrollingTextView(Context context) { 
     super(context); 
    } 

    @Override 
    protected void onFocusChanged(boolean focused, int direction, Rect  previouslyFocusedRect) { 
     if (focused) { 
     super.onFocusChanged(focused, direction, previouslyFocusedRect); 
    } 
    } 

    @Override 
    public void onWindowFocusChanged(boolean focused) { 
     if (focused) { 
      super.onWindowFocusChanged(focused); 
     } 
    } 

    @Override 
    public boolean isFocused() { 
     return true; 
    } 
} 

Тогда в XML

<AutoScrollingTextView 
    android:scrollHorizontally="true" 
    android:ellipsize="marquee" 
    android:marqueeRepeatLimit="marquee_forever"/> 

Это работает !!!