我做了PagerAdapter
,效果非常好但是当我将手机水平放置时,TextView
等许多内容都不可见,因为它们是"低于"手机的屏幕。我知道我可以放ScrollView
,但是这个选项会产生很多错误。
除ScrollView
之外还有其他选项或错误意味着什么?
这是我的代码LinearLayout
没有任何错误,但PagerAdapter
不可滚动。
Java代码:
public class SlideAdapter_info extends PagerAdapter {
Context context;
LayoutInflater inflater;
public SlideAdapter_info(Context context){
this.context = context;
}
@Override
public int getCount() {
return 1;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return (view==(LinearLayout)object);
}
@Override
public void destroyItem(ViewGroup container, int position, Object object{
container.removeView((LinearLayout)object);
}
@NonNull
@Override
public Object instantiateItem(ViewGroup container, int position) {
inflater = (LayoutInflater)
context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.slide_info, container, false);
//other code to set the textviews and the imageview
container.addView(view);
return view;
}
}
xml
代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/slidelinear_info"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<TextView /> ....
<!-- This allows me to have a circle shaped image-->
<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/slideimg"
android:layout_width="200dp"
android:layout_height="200dp"
android:paddingTop="10dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
app:civ_border_color="@color/black"
app:civ_border_width="3dp" />
<TextView /> ....
</LinearLayout>
这是结果:(水平)
这是结果:(垂直)
如果不是LinearLayout
我放ScrollView
,Android Studio
会给我这个错误:
java.lang.IllegalStateException: ScrollView can host only one direct child
at esame.progetto.xhondar.github.com.info.SlideAdapter_info.instantiateItem(SlideAdapter_info.java:87)
这是一行:
View view = inflater.inflate(R.layout.slide_info, container, false);
答案 0 :(得分:2)
MyClass myClass
QObject *home = object->findChild<QObject*>("homeButton"); // I'm able to connect to every Object in the main.qml or home.qml
QObject::connect(home,SIGNAL(qmlSignal(Qstring)), &myClass, SLOT(cppSlot(QString)));
connect( myClass, MyClass::emitWhenQMLIsAlreadyOnTheStack, this, [this](){
QObject *test = newobject->findChild<QObject*>("test"); // Now you should be able to connect
QObject::connect(test,SIGNAL(qmlSignal(Qstring)), &myClass, SLOT(cppSlot(QString));
});
告诉您确切的问题所在。只需将java.lang.IllegalStateException: ScrollView can host only one direct child
转换为LinearLayout
,就可以有多个孩子。如果您希望当前布局在ScrollView
内滚动,则需要将ViewPager
与LinearLayout
包装在布局xml文件中。
ScrollView