【问题标题】:How a TextView never go out of the screen if the user scroll Down?如果用户向下滚动,TextView 如何永远不会离开屏幕?
【发布时间】:2012-07-16 15:58:59
【问题描述】:

我是一名 android 中级开发人员,我需要有人过期才能在我的内容活动中发挥作用;

这是我的内容活动:

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
  ....
 // How this TextView never go out of the screen if the user scroll Down
  <TextView ... />  
  ....
</ScrollView>

*我做了什么:

   <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
   android:layout_height="fill_parent"
    android:orientation="vertical" >

  <TextView ... android:visibility="gone" />

    <ScrollView
     android:layout_width="match_parent"
    android:layout_height="match_parent" >
    ....
  // 
 <TextView ...android:visibility="visible"/>
  ....
  </ScrollView>
 </FrameLayout>

我想过有 2 个 TextView,一个在顶部不可见,另一个可见。 当用户向下滚动并在第二个 TextView 消失之前,我将第一个 textView 设置为可见。

这是一个好方法吗?如果有怎么办?

【问题讨论】:

  • 您能否更详细地解释您的问题。谢谢
  • @M'hamed :很简单,不要将TextView 放在ScrollView 中。

标签: android layout scrollview


【解决方案1】:

关注这个帖子,真的很好。请注意,从那里你可以做一些很棒的事情! Here you go :)

【讨论】:

  • :) 享受吧!您还可以使用更多算法将其同时扩展到多个视图。
【解决方案2】:

尝试将 TextView 放在 scrollView 之外。 IE。

<LinearLayout> 
<EditText /> 
    <LinearLayout> 
       <ScrollView></ScrollView>  
    </LinearLayout> 
</Linearlayout> 

试一试,对不起格式

【讨论】:

  • 但这就是诀窍 :D 让 textview 在滚动视图中但永远不会出去。有没有办法跟踪滚动视图的位置?
【解决方案3】:

根据我从您的问题中了解到的情况,您正在寻找“将您的 textView 放在 ScrollView 之外并在 TextView 和 ScrollView 之间建立相对布局关系,这样 TextView 将固定在顶部位置”。谢谢

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView"
        android:layout_alignParentTop="true"
        android:text="VISIBLE EVERY TIME"
        android:visibility="visible" 
         android:layout_width="match_parent"
        android:layout_height="50dp"
        />

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

</RelativeLayout>

【讨论】:

  • 是的,我知道......但这不是我想做的...... textView 在滚动视图中但永远不会出去!
  • 永远不出去是什么意思?
  • 这个想法是使用同步滚动技术从 ScrollView 内容中获取某个视图,并让它浮动到屏幕顶部,否则它会滚动到屏幕外。如果您好奇,请查看最后的回复...谢谢 Salman :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-12-06
  • 1970-01-01
  • 1970-01-01
  • 2018-07-14
  • 2020-09-19
  • 1970-01-01
  • 2015-12-14
相关资源
最近更新 更多