您可能会猜到我是Android Studio的初学者。
我试图在布局中放置import sys
max = 5
for counter in range(max):
# Input miles to be converted
miles = float(input('Enter the number of miles to convert to kilometers:'))
if miles >= 0:
# May as well defer calculation of milesToKms until we know
# the miles value is valid
milesToKms = miles * 1.6 # miles to kilometers formula
print('Miles converted:', miles)
print('Kilometers:', milesToKms) #display kilometers result
break
else: # No need for elif miles < 0; anything not valid is invalid
print('Invalid value entered.')
else:
# sys.exit is correct way to exit program, and it can output error for you
sys.exit('Too many invalid entries submitted.')
,这是我需要的BottomNavigationView
,但似乎无法解决。
这是我能做的最好的事情,但是SearchView
仍然没有出现:
BottomNavigationView
如果有人有任何想法,我想得到一些帮助,谢谢!
编辑:这是活动-(我将xml的名称改名为activity_main.xml,以便可以使用绑定)
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.v7.widget.SearchView
android:id="@+id/search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true" />
<ListView
android:id="@+id/list_view"
android:layout_width="fill_parent"
android:layout_height="450dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/search" />
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
menu="@menu/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:background="?android:attr/windowBackground"
/>
</RelativeLayout>
</layout>
}
答案 0 :(得分:1)
这是工作代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.SearchView
android:id="@+id/search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true" />
<ListView
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/navigation"
android:layout_below="@+id/search" />
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:background="?android:attr/windowBackground"
app:menu="@menu/navigation" />
</RelativeLayout>