gridview不显示横向android中的所有行

时间:2016-10-24 05:19:49

标签: android gridview scrollview landscape

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginBottom="0dp"
    android:layout_marginTop="0dp">

    <ScrollView
        android:id="@+id/scrollView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">

        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/calendar_bg_orange"
            android:orientation="vertical">

            <Button
                android:id="@+id/selectedDayMonthYear"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:background="@drawable/calendar_top_header"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="#FFFFFF"/>

            <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <ImageView
                    android:id="@+id/prevMonth"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/calendar_left_arrow_selector"/>

                <Button
                    android:id="@+id/currentMonth"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.6"
                    android:background="@drawable/calendar_bar"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textColor="#FFFFFF"/>

                <ImageView
                    android:id="@+id/nextMonth"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/calendar_right_arrow_selector"/>
            </LinearLayout>

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center">

                <ImageView
                    android:id="@+id/calendarheader"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:src="@drawable/blue_bg_with_text"/>
            </LinearLayout>

            <GridView
                android:id="@+id/calendar"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:columnWidth="100px"
                android:footerDividersEnabled="false"
                android:numColumns="@integer/grid_rows"
                android:stretchMode="columnWidth"/>

            <Button
                android:id="@+id/getAttendance"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:background="@drawable/button"
                android:text="Attendance"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:textColor="#FFFFFF"/>

        </LinearLayout>
    </ScrollView>
</RelativeLayout>

来自Adapter的getView()

public View getView(int position, View convertView, ViewGroup parent)
    {
        View row = convertView;
        if (row == null)
        {
            LayoutInflater inflater = (LayoutInflater) _context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            row = inflater.inflate(R.layout.day_gridcell, parent, false);
        } 

在纵向模式下,显示效果如下:

enter image description here

在横向模式下仅显示1行

enter image description here

我已经尝试将列规范放在res文件夹中的integers.xml中,但没有成功。请帮助。

1 个答案:

答案 0 :(得分:0)

我可以看到的一个原因是您的按钮的宽度为public sealed partial class MainPage : Page { public MainPage() { this.InitializeComponent(); } private void btnClick_Click(object sender, RoutedEventArgs e) { Flyout flyout = new Flyout(); TextBlock tbContent = new TextBlock { Text= "this is a flyout content" }; flyout.Content = tbContent; flyout.ShowAt(myEle); } } ,这会在wrap_content模式和类似问题中留下一些空间。

您可能需要为横向视图创建特定的布局。检查this

这将为您提供额外的腿部空间,以根据您的屏幕尺寸自定义您的布局。