ScrollView中的LinearLayout

时间:2015-02-26 05:24:28

标签: android xml android-layout 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>

3 个答案:

答案 0 :(得分:7)

更改android:layout_gravity =&#34; center&#34;到android:gravity =&#34; center&#34;在LinearLayout中,将所有ImageView的宽度和高度更改为&#34; wrap_content&#34;。

答案 1 :(得分:1)

线性布局的高度应与父级匹配,图像的宽度和高度必须为换行内容。这可能会对你有帮助。

答案 2 :(得分:0)

使用此代码......

<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>