java – Android ScrollView不是从顶部开始,而是在GridView的开头
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java – Android ScrollView不是从顶部开始,而是在GridView的开头,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3716字,纯文字阅读大概需要6分钟。
内容图文
我有一个ScrollView的问题,里面有个性化的GridView和其他视图.第一次启动Activity时,ScrollView从顶部开始,但是如果我访问Activity其他时候ScrollView从头开始GridView.I使用了this link中为我的GridView找到的ExpandableHeightGridView类.
Activity布局的xml代码是这样的:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollViewLuogo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff" >
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="150dp"
android:layout_height="100dp"
android:layout_marginLeft="14dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:adjustViewBounds="true"
android:maxHeight="200dp"
android:maxWidth="200dp"
android:scaleType="fitXY"
android:src="@android:drawable/ic_menu_gallery" />
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="vertical" >
<TextView
android:id="@+id/nomeTVActivityLuogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="17sp"
android:textColor="#005788" />
<TextView
android:id="@+id/indirizzoTVActivityLuogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayout2"
android:layout_marginTop="10dp"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageViewMappaLuogo"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="14dp"
android:layout_marginRight="14dp"
android:layout_marginTop="5dp"
android:scaleType="fitXY"
android:src="@drawable/sfondo_mappa" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="14dp"
android:text="Immagini"
android:textColor="#97d6f9" />
<View
android:layout_width="fill_parent"
android:layout_height="2dp"
android:layout_marginLeft="14dp"
android:layout_marginRight="14dp"
android:layout_marginTop="5dp"
android:background="#97d6f9" />
<com.example.mappine.ExpandableHeightGridView
android:id="@+id/gridViewLuogo"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:numColumns="3" >
</com.example.mappine.ExpandableHeightGridView>
</LinearLayout>
</RelativeLayout>
我尝试过使用代码scrollView.fullScroll(ScrollView.FOCUS_UP);但它没有用.甚至使用scrollView.scrollTo(0,0);我没有成功.
唯一有效的代码是:
scrollView.post(new Runnable()
{
public void run() {
scrollViewLuogo.fullScroll(ScrollView.FOCUS_UP);
}
});
但它从GridView的顶部到屏幕的顶部进行快速动画,我不喜欢它.
有什么建议??
解决方法:
解:
好的抱歉,如果这是一个迟到的回复,但我偶然发现同样的问题(只是我使用的是ListView),并且经过一些试验和错误,我找到了解决方案:
基本上问题在于GridView / ListView子项在您“hack”并使用ExpandableHeightGridView调整其内容时自动请求父焦点(ScrollView),这在渲染布局后发生,因此您在尝试滚动它时会看到该动画使用scrollTo()(在创建布局之后发生,并且在调整gridView后调整大小,因此任何通用回调都无法以编程方式处理此问题).
那么,我发现最简单的解决方案是简单地在ListView / GridView上禁用focusable属性:
listView.setFocusable(false);
这样,当您第一次进入活动时,焦点将默认,而不依赖于Listview / GridView.
一切正常=)
内容总结
以上是互联网集市为您收集整理的java – Android ScrollView不是从顶部开始,而是在GridView的开头全部内容,希望文章能够帮你解决java – Android ScrollView不是从顶部开始,而是在GridView的开头所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。