ScrollView 中的 LinearLayout
LinearLayout inside ScrollView
在这个 xml 中,我试图显示 7 个 ImageView,因此我使用的是 ScrollView。但是,在模拟器中它不会完全显示第一个 ImageView。仅显示其下半部分。我该如何解决?
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/homescreen_bg">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical" >
<ImageView
android:id="@+id/header"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:contentDescription="@string/Homescreen_header"
android:src="@drawable/logoheader" />
<ImageView
android:id="@+id/empinfo_logo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:contentDescription="@string/Homescreen_emp_info"
android:src="@drawable/employee_info" />
<ImageView
android:id="@+id/leaveinfo_logo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:contentDescription="@string/Homescreen_leave_info"
android:src="@drawable/leave_info" />
<ImageView
android:id="@+id/holidays_logo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:contentDescription="@string/Homescreen_holidays"
android:src="@drawable/holidays" />
<ImageView
android:id="@+id/leavereq_logo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:contentDescription="@string/Homescreen_leave_req"
android:src="@drawable/leave_request" />
<ImageView
android:id="@+id/leavestatus_logo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:contentDescription="@string/Homescreen_leave_status"
android:src="@drawable/leave_status" />
<ImageView
android:id="@+id/logout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:contentDescription="@string/logout_button"
android:src="@drawable/logout" />
</LinearLayout>
</ScrollView>
线性布局的高度应与父级相匹配,图像的宽度和高度必须为环绕内容。这可能对你有帮助。
使用此代码....
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/homescreen_bg">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="@+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:contentDescription="@string/Homescreen_header"
android:src="@drawable/logoheader" />
<ImageView
android:id="@+id/empinfo_logo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:contentDescription="@string/Homescreen_emp_info"
android:src="@drawable/employee_info" />
<ImageView
android:id="@+id/leaveinfo_logo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:contentDescription="@string/Homescreen_leave_info"
android:src="@drawable/leave_info" />
<ImageView
android:id="@+id/holidays_logo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:contentDescription="@string/Homescreen_holidays"
android:src="@drawable/holidays" />
<ImageView
android:id="@+id/leavereq_logo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:contentDescription="@string/Homescreen_leave_req"
android:src="@drawable/leave_request" />
<ImageView
android:id="@+id/leavestatus_logo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:contentDescription="@string/Homescreen_leave_status"
android:src="@drawable/leave_status" />
<ImageView
android:id="@+id/logout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:contentDescription="@string/logout_button"
android:src="@drawable/logout" />
</LinearLayout>
将LinearLayout中的android:layout_gravity = "center"改为android:gravity="center",所有ImageView的宽高改为"wrap_content".
在这个 xml 中,我试图显示 7 个 ImageView,因此我使用的是 ScrollView。但是,在模拟器中它不会完全显示第一个 ImageView。仅显示其下半部分。我该如何解决?
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/homescreen_bg">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical" >
<ImageView
android:id="@+id/header"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:contentDescription="@string/Homescreen_header"
android:src="@drawable/logoheader" />
<ImageView
android:id="@+id/empinfo_logo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:contentDescription="@string/Homescreen_emp_info"
android:src="@drawable/employee_info" />
<ImageView
android:id="@+id/leaveinfo_logo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:contentDescription="@string/Homescreen_leave_info"
android:src="@drawable/leave_info" />
<ImageView
android:id="@+id/holidays_logo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:contentDescription="@string/Homescreen_holidays"
android:src="@drawable/holidays" />
<ImageView
android:id="@+id/leavereq_logo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:contentDescription="@string/Homescreen_leave_req"
android:src="@drawable/leave_request" />
<ImageView
android:id="@+id/leavestatus_logo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:contentDescription="@string/Homescreen_leave_status"
android:src="@drawable/leave_status" />
<ImageView
android:id="@+id/logout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:contentDescription="@string/logout_button"
android:src="@drawable/logout" />
</LinearLayout>
</ScrollView>
线性布局的高度应与父级相匹配,图像的宽度和高度必须为环绕内容。这可能对你有帮助。
使用此代码....
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/homescreen_bg">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="@+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:contentDescription="@string/Homescreen_header"
android:src="@drawable/logoheader" />
<ImageView
android:id="@+id/empinfo_logo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:contentDescription="@string/Homescreen_emp_info"
android:src="@drawable/employee_info" />
<ImageView
android:id="@+id/leaveinfo_logo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:contentDescription="@string/Homescreen_leave_info"
android:src="@drawable/leave_info" />
<ImageView
android:id="@+id/holidays_logo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:contentDescription="@string/Homescreen_holidays"
android:src="@drawable/holidays" />
<ImageView
android:id="@+id/leavereq_logo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:contentDescription="@string/Homescreen_leave_req"
android:src="@drawable/leave_request" />
<ImageView
android:id="@+id/leavestatus_logo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:contentDescription="@string/Homescreen_leave_status"
android:src="@drawable/leave_status" />
<ImageView
android:id="@+id/logout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:contentDescription="@string/logout_button"
android:src="@drawable/logout" />
</LinearLayout>
将LinearLayout中的android:layout_gravity = "center"改为android:gravity="center",所有ImageView的宽高改为"wrap_content".