我将图像视图添加到线性布局中,然后将该线性布局添加到滚动视图中。我用窗口管理器显示滚动视图,因为这都是通过一个服务实现的。我可以看到滚动条,当我上下拖动时,滚动条会移动,但图像视图不会移动。
下面是我的代码:
// 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);发布于 2013-03-21 18:28:08
你可以试一下,如下所示:
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-21 18:31:26
你有一个固定的高度为trayAppList线性布局以及“滚动”ScrollView。因此ScrollView不能滚动。
创建您的ScrollView FILL_PARENT,并确保滚动布局中的内容超出屏幕,然后您将能够滚动。
发布于 2015-01-11 16:00:13
把你的卷轴布局放在线性布局里面。
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);
}https://stackoverflow.com/questions/15544807
复制相似问题