0

我将图像视图添加到线性布局,然后将该线性布局添加到滚动视图。我正在使用窗口管理器显示滚动视图,因为这一切都发生在服务中。我可以看到滚动条,当我上下拖动时,滚动条会移动,但图像视图不会。

这是我的代码:

// 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);
4

3 回答 3

0

将滚动布局放在线性布局内。

info_content_layout.xml

<?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>

代码

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);
}
于 2015-01-11T08:00:13.287 回答
0

您可以尝试如下:

ScrollView scroll = new ScrollView(context);
scroll.setBackgroundColor(android.R.color.transparent);
scroll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
scroll.addView(yourTableView);
于 2013-03-21T10:28:07.573 回答
0

您有一个固定高度的 trayAppList 线性布局以及“滚动”ScrollView。所以 ScrollView 不能滚动。

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

于 2013-03-21T10:31:26.303 回答