首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >滚动视图不滚动

滚动视图不滚动
EN

Stack Overflow用户
提问于 2013-03-21 18:22:41
回答 3查看 863关注 0票数 0

我将图像视图添加到线性布局中,然后将该线性布局添加到滚动视图中。我用窗口管理器显示滚动视图,因为这都是通过一个服务实现的。我可以看到滚动条,当我上下拖动时,滚动条会移动,但图像视图不会移动。

下面是我的代码:

代码语言:javascript
复制
// define the two views
    scroll = new ScrollView(this);
    trayAppList = new LinearLayout(this);

//define basic layout properties
trayAppList.setOrientation(LinearLayout.VERTICAL);
        width = 50;
        height = display.getHeight();

        // shortcut list container
        lstParams = new WindowManager.LayoutParams(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.FILL_PARENT, WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN, PixelFormat.TRANSLUCENT);
        lstParams.gravity = dockLocation;
        scroll.setLayoutParams(new android.view.ViewGroup.LayoutParams(WindowManager.LayoutParams.WRAP_CONTENT, height));

//define window manager
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);

//now display views

    scroll.setScrollContainer(true);
scroll.addView(trayAppList);
wm.addView(scroll, lstParams);
EN

回答 3

Stack Overflow用户

发布于 2013-03-21 18:28:08

你可以试一下,如下所示:

代码语言:javascript
复制
ScrollView scroll = new ScrollView(context);
scroll.setBackgroundColor(android.R.color.transparent);
scroll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
scroll.addView(yourTableView);
票数 0
EN

Stack Overflow用户

发布于 2013-03-21 18:31:26

你有一个固定的高度为trayAppList线性布局以及“滚动”ScrollView。因此ScrollView不能滚动。

创建您的ScrollView FILL_PARENT,并确保滚动布局中的内容超出屏幕,然后您将能够滚动。

票数 0
EN

Stack Overflow用户

发布于 2015-01-11 16:00:13

把你的卷轴布局放在线性布局里面。

info_content_layout.xml

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/container"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent">

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

        <LinearLayout
            android:id="@+id/list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

        </LinearLayout>

    </ScrollView>

</LinearLayout>

代码

代码语言:javascript
复制
LinearLayout container = (LinearLayout) LayoutInflater.from(getApplicationContext()).inflate(R.layout.info_content_layout, null);
WindowManager.LayoutParams containerParams = new WindowManager.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT,WindowManager.LayoutParams.WRAP_CONTENT,WindowManager.LayoutParams.TYPE_PHONE,WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,PixelFormat.TRANSLUCENT);
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
wm.addView(container, containerParams); 

LinearLayout listContainer = (LinearLayout) container.findViewById(R.id.list);
for(int x = 0 ; x <30 ; x++){
    View child =  LayoutInflater.from(this).inflate(R.layout.list_item, null);
    listContainer.addView(child);
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15544807

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档