我正在将图像视图添加到线性布局中,然后将线性布局添加到滚动视图中。我正在使用窗口管理器显示滚动视图,因为这一切都是从服务中发生的。我可以看到滚动条,当我向上和向下拖动时,滚动条会移动,但图像视图不会移动。
这是我的代码:
// 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);
答案 0 :(得分: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);
答案 1 :(得分:0)
您有托盘应用程序线性布局以及“滚动”ScrollView的修复高度。所以ScrollView无法滚动。
制作ScrollView FILL_PARENT,并确保滚动布局中的内容超出屏幕,然后您就可以滚动。
答案 2 :(得分: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);
}