2014-01-20 1 views
1

Я хочу отобразить заголовок textView с текстом заголовка в scrollview, пока я прокручиваю вниз, и этот заголовок не отображается. Я имею в виду, что он прокручивается. В основном я хочу, чтобы freez заголовок на верхней части экрана, когда я прокручиваю вниз, и заголовок загорается и не отображается для пользователя из-за его прокрутки вверх. Вот мой файл XMl. Я хочу заморозить TextView, id = "@ + id/freezed_title_text", когда TextView, id = "@ + id/title_text", прокручивается вверх и не отображается на экране. Спасибо заранее ....Как Freez Title в scrollView, когда заголовок не отображается на дисплее во время прокрутки?

<TextView 
    android:id="@+id/freezed_title_text" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Hello" 
    android:textColor="@color/news_detail_text_textcolor" 
    android:textSize="@dimen/hdpi_news_detail_title_textsize" 
    android:textStyle="bold" 
    android:visibility="gone"/> 

<ScrollView 
    android:id="@+id/scroolview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@color/exp_background" 
    android:fillViewport="true" 
    android:layout_below="@+id/freezed_title_text"> 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="@dimen/news_detail_layout_height" > 

     <TextView 
      android:id="@+id/temp_title_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="@dimen/news_detail_rellayout_marginleft" 
      android:layout_marginRight="@dimen/news_detail_rellayout_marginright" 
      android:text="" 
      android:textColor="@color/news_detail_text_textcolor" 
      android:textSize="@dimen/hdpi_news_detail_title_textsize" 
      android:textStyle="bold" /> 

     <RelativeLayout 
      android:id="@+id/image_parent" 
      android:layout_width="match_parent" 
      android:layout_height="@dimen/news_detail_layout_height" 
      android:layout_below="@+id/temp_title_text" 
      android:layout_marginTop="@dimen/news_detail_margintop" > 

      <ImageView 
       android:id="@+id/largeimage" 
       android:layout_width="match_parent" 
       android:layout_height="fill_parent" 
       android:layout_alignParentTop="true" 
       android:layout_centerHorizontal="true" 
       android:src="@drawable/loadrefresh1" /> 

      <LinearLayout 
       android:id="@+id/like_dislike_parent" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true" 
       android:layout_centerHorizontal="true" 
       android:layout_marginBottom="@dimen/news_detail_linear_marginbottom" 
       android:layout_marginRight="@dimen/news_detail_linear_marginright" > 

       <ImageView 
        android:id="@+id/like" 
        android:layout_width="@dimen/news_detail_img_layoutwidth" 
        android:layout_height="@dimen/news_detail_img_layoutheight" 
        android:layout_marginRight="@dimen/news_detail_img_layoutmarginright" 
        android:src="@drawable/like_bigger" /> 

       <ImageView 
        android:id="@+id/dislike" 
        android:layout_width="@dimen/news_detail_img_layoutwidth" 
        android:layout_height="@dimen/news_detail_img_layoutheight" 
        android:src="@drawable/disklike_bigger" /> 
      </LinearLayout> 
     </RelativeLayout> 

     <RelativeLayout 
      android:id="@+id/relParent" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/image_parent" 
      android:layout_marginLeft="@dimen/news_detail_rellayout_marginleft" 
      android:layout_marginRight="@dimen/news_detail_rellayout_marginright" 
      android:layout_marginTop="@dimen/news_detail_rellayout_margintop" 
      android:orientation="horizontal" > 

      <ImageView 
       android:id="@+id/messageButton" 
       android:layout_width="@dimen/news_detail_img_layoutwidth" 
       android:layout_height="@dimen/news_detail_img_layoutheight" 
       android:layout_marginLeft="@dimen/news_detail_img_layoutmarginleft" 
       android:layout_toLeftOf="@+id/facebookButton" 
       android:src="@drawable/message_bigger" /> 

      <ImageView 
       android:id="@+id/facebookButton" 
       android:layout_width="@dimen/news_detail_img_layoutwidth" 
       android:layout_height="@dimen/news_detail_img_layoutheight" 
       android:layout_marginLeft="@dimen/news_detail_img_layoutmarginleft" 
       android:layout_toLeftOf="@+id/twitterButton" 
       android:src="@drawable/facebook_bigger" /> 

      <ImageView 
       android:id="@+id/twitterButton" 
       android:layout_width="@dimen/news_detail_img_layoutwidth" 
       android:layout_height="@dimen/news_detail_img_layoutheight" 
       android:layout_marginLeft="@dimen/news_detail_img_layoutmarginleft" 
       android:layout_toLeftOf="@+id/linkedinButton" 
       android:src="@drawable/twiter_bigger" /> 

      <ImageView 
       android:id="@+id/linkedinButton" 
       android:layout_width="@dimen/news_detail_img_layoutwidth" 
       android:layout_height="@dimen/news_detail_img_layoutheight" 
       android:layout_alignParentRight="true" 
       android:layout_marginLeft="@dimen/news_detail_img_marginleft" 
       android:layout_marginRight="@dimen/news_detail_img_marginright" 
       android:src="@drawable/linkden_bigger" /> 
     </RelativeLayout> 

     <TextView 
      android:id="@+id/title_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/relParent" 
      android:layout_marginLeft="@dimen/news_detail_rellayout_marginleft" 
      android:layout_marginRight="@dimen/news_detail_rellayout_marginright" 
      android:textColor="@color/news_detail_text_textcolor" 
      android:textSize="@dimen/hdpi_news_detail_title_textsize" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/EMPTY" 
      android:layout_width="match_parent" 
      android:layout_height="@dimen/news_detail_text_layout_height" 
      android:layout_below="@+id/title_text" 
      android:textColor="@color/newsview_text_colro" /> 

     <TextView 
      android:id="@+id/datailtext" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/EMPTY" 
      android:layout_marginLeft="@dimen/news_detail_text_marginleft" 
      android:layout_marginRight="@dimen/news_detail_text_marginright" 
      android:layout_marginTop="@dimen/news_detail_text_margintop" 
      android:text="@string/detailed_text" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:textColor="@color/news_detail_text_textcolor" 
      android:textSize="@dimen/hdpi_news_detail_text_textsize" /> 

     <LinearLayout 
      android:id="@+id/line" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/datailtext" 
      android:background="@color/exp_background" 
      android:orientation="vertical" > 

      <View 
       android:layout_width="250sp" 
       android:layout_height="2dp" 
       android:layout_gravity="center_horizontal" 
       android:layout_marginTop="10sp" 
       android:background="@color/exp_background" /> 
     </LinearLayout> 

     <RelativeLayout 
      android:id="@+id/keyword_layout" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_below="@+id/line" 
      android:layout_marginRight="@dimen/news_detail_text_marginright" 
      android:orientation="horizontal" > 
     </RelativeLayout> 

     <LinearLayout 
      android:id="@+id/line_2" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/keyword_layout" 
      android:layout_marginLeft="@dimen/news_detail_text_marginleft" 
      android:layout_marginRight="@dimen/news_detail_text_marginright" 
      android:orientation="horizontal" > 

      <View 
       android:id="@+id/l1" 
       android:layout_width="130sp" 
       android:layout_height="1dp" 
       android:layout_gravity="center" 
       android:layout_marginBottom="10sp" 
       android:layout_marginTop="10sp" 
       android:background="#6f6f6f" /> 

      <TextView 
       android:id="@+id/black_dot" 
       android:layout_width="11dp" 
       android:layout_height="11dp" 
       android:layout_gravity="center" 
       android:layout_marginLeft="@dimen/news_detail_img_layoutmarginleft" 
       android:layout_marginRight="@dimen/news_detail_img_layoutmarginleft" 
       android:background="@drawable/round_dot" 
       android:textColor="@color/newsview_text_colro" /> 

      <View 
       android:id="@+id/l2" 
       android:layout_width="130sp" 
       android:layout_height="1dp" 
       android:layout_gravity="center" 
       android:layout_marginBottom="10sp" 
       android:layout_marginRight="0dp" 
       android:layout_marginTop="10sp" 
       android:background="#6f6f6f" /> 
     </LinearLayout> 

     <TextView 
      android:id="@+id/txt_related_news" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/line_2" 
      android:layout_centerHorizontal="true" 
      android:layout_centerVertical="true" 
      android:layout_marginLeft="@dimen/news_detail_text_marginleft" 
      android:layout_marginRight="@dimen/news_detail_text_marginright" 
      android:background="#1f1f21" 
      android:gravity="center" 
      android:paddingBottom="3dp" 
      android:paddingTop="3dp" 
      android:text="Related News" 
      android:textColor="#d1d1d3" 
      android:textSize="18sp" /> 

     <LinearLayout 
      android:id="@+id/related_container" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/txt_related_news" 
      android:layout_marginLeft="@dimen/news_detail_text_marginleft" 
      android:layout_marginRight="@dimen/news_detail_text_marginright" 
      android:layout_marginTop="2dp" 
      android:orientation="vertical" > 
     </LinearLayout> 

     <TextView 
      android:id="@+id/urlTextBottom" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/related_container" 
      android:layout_marginLeft="@dimen/news_detail_text_marginleft" 
      android:layout_marginRight="@dimen/news_detail_text_marginright" 
      android:layout_marginTop="10sp" 
      android:lines="2" 
      android:text="asvcagvcgavscjhasjahvjvsachv" 
      android:textColor="@color/news_detail_text_textcolor" 
      android:textColorLink="@color/news_detail_text_textcolor" 
      android:textSize="@dimen/hdpi_news_detail_text_textsize" /> 
    </RelativeLayout> 
</ScrollView> 

enter image description here

+0

добавить изображение того, что вы хотите достичь и какой у вас текущий код? Отправьте его здесь – Prateek

+0

Теперь добавлен XML-код и изображение с разрешением Desire. Так что plz помогите мне решить мою проблему –

ответ

0

Вы можете достичь этого путем добавления LinearLayout с заголовком и Scrollview:

<TextView 
    android:id="@+id/freezed_title_text" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Hello" 
    android:textColor="@color/news_detail_text_textcolor" 
    android:textSize="@dimen/hdpi_news_detail_title_textsize" 
    android:textStyle="bold" 
    android:visibility="gone"/> 


    <LinearLayout android:layout_width="fill_parent" 
      android:layout_height="fill_parent" android:layout_below="@+id/freezed_title_text" 
    android:orientation="vertical"> 
    <TextView 
      android:id="@+id/temp_title_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="@dimen/news_detail_rellayout_marginleft" 
      android:layout_marginRight="@dimen/news_detail_rellayout_marginright" 
      android:text="" 
      android:textColor="@color/news_detail_text_textcolor" 
      android:textSize="@dimen/hdpi_news_detail_title_textsize" 
      android:textStyle="bold" /> 

<ScrollView 
    android:id="@+id/scroolview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@color/exp_background" 
    android:fillViewport="true" 
    > 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="@dimen/news_detail_layout_height" > 


     <RelativeLayout 
      android:id="@+id/image_parent" 
      android:layout_width="match_parent" 
      android:layout_height="@dimen/news_detail_layout_height" 
      android:layout_marginTop="@dimen/news_detail_margintop" > 

      <ImageView 
       android:id="@+id/largeimage" 
       android:layout_width="match_parent" 
       android:layout_height="fill_parent" 
       android:layout_alignParentTop="true" 
       android:layout_centerHorizontal="true" 
       android:src="@drawable/loadrefresh1" /> 

      <LinearLayout 
       android:id="@+id/like_dislike_parent" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true" 
       android:layout_centerHorizontal="true" 
       android:layout_marginBottom="@dimen/news_detail_linear_marginbottom" 
       android:layout_marginRight="@dimen/news_detail_linear_marginright" > 

       <ImageView 
        android:id="@+id/like" 
        android:layout_width="@dimen/news_detail_img_layoutwidth" 
        android:layout_height="@dimen/news_detail_img_layoutheight" 
        android:layout_marginRight="@dimen/news_detail_img_layoutmarginright" 
        android:src="@drawable/like_bigger" /> 

       <ImageView 
        android:id="@+id/dislike" 
        android:layout_width="@dimen/news_detail_img_layoutwidth" 
        android:layout_height="@dimen/news_detail_img_layoutheight" 
        android:src="@drawable/disklike_bigger" /> 
      </LinearLayout> 
     </RelativeLayout> 

     <RelativeLayout 
      android:id="@+id/relParent" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/image_parent" 
      android:layout_marginLeft="@dimen/news_detail_rellayout_marginleft" 
      android:layout_marginRight="@dimen/news_detail_rellayout_marginright" 
      android:layout_marginTop="@dimen/news_detail_rellayout_margintop" 
      android:orientation="horizontal" > 

      <ImageView 
       android:id="@+id/messageButton" 
       android:layout_width="@dimen/news_detail_img_layoutwidth" 
       android:layout_height="@dimen/news_detail_img_layoutheight" 
       android:layout_marginLeft="@dimen/news_detail_img_layoutmarginleft" 
       android:layout_toLeftOf="@+id/facebookButton" 
       android:src="@drawable/message_bigger" /> 

      <ImageView 
       android:id="@+id/facebookButton" 
       android:layout_width="@dimen/news_detail_img_layoutwidth" 
       android:layout_height="@dimen/news_detail_img_layoutheight" 
       android:layout_marginLeft="@dimen/news_detail_img_layoutmarginleft" 
       android:layout_toLeftOf="@+id/twitterButton" 
       android:src="@drawable/facebook_bigger" /> 

      <ImageView 
       android:id="@+id/twitterButton" 
       android:layout_width="@dimen/news_detail_img_layoutwidth" 
       android:layout_height="@dimen/news_detail_img_layoutheight" 
       android:layout_marginLeft="@dimen/news_detail_img_layoutmarginleft" 
       android:layout_toLeftOf="@+id/linkedinButton" 
       android:src="@drawable/twiter_bigger" /> 

      <ImageView 
       android:id="@+id/linkedinButton" 
       android:layout_width="@dimen/news_detail_img_layoutwidth" 
       android:layout_height="@dimen/news_detail_img_layoutheight" 
       android:layout_alignParentRight="true" 
       android:layout_marginLeft="@dimen/news_detail_img_marginleft" 
       android:layout_marginRight="@dimen/news_detail_img_marginright" 
       android:src="@drawable/linkden_bigger" /> 
     </RelativeLayout> 

     <TextView 
      android:id="@+id/title_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/relParent" 
      android:layout_marginLeft="@dimen/news_detail_rellayout_marginleft" 
      android:layout_marginRight="@dimen/news_detail_rellayout_marginright" 
      android:textColor="@color/news_detail_text_textcolor" 
      android:textSize="@dimen/hdpi_news_detail_title_textsize" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/EMPTY" 
      android:layout_width="match_parent" 
      android:layout_height="@dimen/news_detail_text_layout_height" 
      android:layout_below="@+id/title_text" 
      android:textColor="@color/newsview_text_colro" /> 

     <TextView 
      android:id="@+id/datailtext" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/EMPTY" 
      android:layout_marginLeft="@dimen/news_detail_text_marginleft" 
      android:layout_marginRight="@dimen/news_detail_text_marginright" 
      android:layout_marginTop="@dimen/news_detail_text_margintop" 
      android:text="@string/detailed_text" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:textColor="@color/news_detail_text_textcolor" 
      android:textSize="@dimen/hdpi_news_detail_text_textsize" /> 

     <LinearLayout 
      android:id="@+id/line" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/datailtext" 
      android:background="@color/exp_background" 
      android:orientation="vertical" > 

      <View 
       android:layout_width="250sp" 
       android:layout_height="2dp" 
       android:layout_gravity="center_horizontal" 
       android:layout_marginTop="10sp" 
       android:background="@color/exp_background" /> 
     </LinearLayout> 

     <RelativeLayout 
      android:id="@+id/keyword_layout" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_below="@+id/line" 
      android:layout_marginRight="@dimen/news_detail_text_marginright" 
      android:orientation="horizontal" > 
     </RelativeLayout> 

     <LinearLayout 
      android:id="@+id/line_2" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/keyword_layout" 
      android:layout_marginLeft="@dimen/news_detail_text_marginleft" 
      android:layout_marginRight="@dimen/news_detail_text_marginright" 
      android:orientation="horizontal" > 

      <View 
       android:id="@+id/l1" 
       android:layout_width="130sp" 
       android:layout_height="1dp" 
       android:layout_gravity="center" 
       android:layout_marginBottom="10sp" 
       android:layout_marginTop="10sp" 
       android:background="#6f6f6f" /> 

      <TextView 
       android:id="@+id/black_dot" 
       android:layout_width="11dp" 
       android:layout_height="11dp" 
       android:layout_gravity="center" 
       android:layout_marginLeft="@dimen/news_detail_img_layoutmarginleft" 
       android:layout_marginRight="@dimen/news_detail_img_layoutmarginleft" 
       android:background="@drawable/round_dot" 
       android:textColor="@color/newsview_text_colro" /> 

      <View 
       android:id="@+id/l2" 
       android:layout_width="130sp" 
       android:layout_height="1dp" 
       android:layout_gravity="center" 
       android:layout_marginBottom="10sp" 
       android:layout_marginRight="0dp" 
       android:layout_marginTop="10sp" 
       android:background="#6f6f6f" /> 
     </LinearLayout> 

     <TextView 
      android:id="@+id/txt_related_news" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/line_2" 
      android:layout_centerHorizontal="true" 
      android:layout_centerVertical="true" 
      android:layout_marginLeft="@dimen/news_detail_text_marginleft" 
      android:layout_marginRight="@dimen/news_detail_text_marginright" 
      android:background="#1f1f21" 
      android:gravity="center" 
      android:paddingBottom="3dp" 
      android:paddingTop="3dp" 
      android:text="Related News" 
      android:textColor="#d1d1d3" 
      android:textSize="18sp" /> 

     <LinearLayout 
      android:id="@+id/related_container" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/txt_related_news" 
      android:layout_marginLeft="@dimen/news_detail_text_marginleft" 
      android:layout_marginRight="@dimen/news_detail_text_marginright" 
      android:layout_marginTop="2dp" 
      android:orientation="vertical" > 
     </LinearLayout> 

     <TextView 
      android:id="@+id/urlTextBottom" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/related_container" 
      android:layout_marginLeft="@dimen/news_detail_text_marginleft" 
      android:layout_marginRight="@dimen/news_detail_text_marginright" 
      android:layout_marginTop="10sp" 
      android:lines="2" 
      android:text="asvcagvcgavscjhasjahvjvsachv" 
      android:textColor="@color/news_detail_text_textcolor" 
      android:textColorLink="@color/news_detail_text_textcolor" 
      android:textSize="@dimen/hdpi_news_detail_text_textsize" /> 
    </RelativeLayout> 
</ScrollView> 
</LinearLayout>