我想在Google Maps Navigational BottomSheet中创建一个导航底部工作表,其中我们有路线的路线列表。我正在使用android的BottomSheetBehaviour来打开底部表格。我目前面临的问题是当弹出时,listview不会显示在底部工作表布局中。视图只是空白。我还尝试在NestedScrollView中自己膨胀视图以获得相同的结果,但这也没有显示出来。
这是我的底片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/bottomSheet1"
android:orientation="vertical"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:elevation="4dp"
android:background="@color/white"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
android:clipToPadding="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="This is a sheet with listview."
android:textSize="20dp"
android:layout_marginTop="10dp"
android:textColor="@color/primaryText"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:text="This is a secondary text!"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<android.support.v4.widget.NestedScrollView
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/nestedLinearLayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<ListView
android:id="@+id/bottomSheetListview"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
在我的java代码中,
View bottomSheetView = findViewById(R.id.bottomSheet1);
ListView listView = (ListView) findViewById(R.id.bottomSheetListview);
List<String> listData = getListData(); //returns a simple array list of strings, about 15 items
listView.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,listData));
mBottomSheetBehavior = BottomSheetBehavior.from(bottomSheetView);
mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
我在这里做错了吗?为什么不显示litview或scrollview。
被修改 我的整个活动
public class BottomSheetActivity extends AppCompatActivity {
private static final String TAG = "==> BottomSheetActivity";
BottomSheetBehavior mBottomSheetBehavior;
Button peek;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bottom_sheet);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
this.peek = (Button) findViewById(R.id.peek);
peek.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showSheet1();
}
});
}
private List<String> getListData(){
List<String> stringList = new ArrayList<>();
for (int i = 0; i < 15; i++) {
stringList.add("This is string number "+i);
}
return stringList;
}
private void showSheet1(){
if(mBottomSheetBehavior != null){
//hide any previous bottom sheets
mBottomSheetBehavior.setHideable(true);
mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
}
//initialize a new sheet
View bottomSheetView = findViewById(R.id.bottomSheet1);
ListView listView = (ListView) bottomSheetView.findViewById(R.id.bottomSheetListview);
listView.setVisibility(View.VISIBLE);
List<String> listData = getListData();
listView.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,listData));
mBottomSheetBehavior = BottomSheetBehavior.from(bottomSheetView);
mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
}
}
activity_bottom_sheet.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.vedamic.androidtutorial.BottomSheetActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_bottom_sheet" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_dialog_email" />
<include layout="@layout/layout_bottom_sheet_1" />
</android.support.design.widget.CoordinatorLayout>
content_bottom_shee.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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.vedamic.androidtutorial.BottomSheetActivity"
tools:showIn="@layout/activity_bottom_sheet">
<Button
android:id="@+id/peek"
android:text="peek 1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/expand"
android:text="peek 2"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/flipboardSheet"
android:text="Flipbard BottomSheets"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ListView
android:id="@+id/testListView"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
答案 0 :(得分:2)
我导入了你的xml并且android工作室“预览”确实显示带有def set_true(true_fields=[])
attr_hash = {}
true_fields.each { |field| attr_hash[field] = true }
update_attributes(hash)
end
的{{1}}占据了整个空间,因此NestedScrollView
没有留下空间。
将android:layout_height="match_parent"
设置为ListView
时NestedScrollView
有足够的空间。
所以现在唯一的原因就是因为你的android:visibility="gone"
是空的?
修改强>
好的,我实现了所有信息,风格非常混乱。首先,窥视1按钮位于工具栏后面。
但我仍然可以点击它,所以会发生这种情况:
答案 1 :(得分:1)
首先不要让listview的可见性消失。底部应该知道它的大小。如果您需要提高其可见性,请在创建底页后完成。
在底页中填写content_bottom_shee.xml parent linearlayout
android:fillViewport="true"