簡體   English   中英

更改方向時可以看到/不看到Android Image

[英]Android Image is seen/not seen when orientation is changed

我在ScrollViewImageView遇到一些問題。

我想要的是:

我總是在屏幕頂部設置ImageView 然后,我有一個ScrollView ,其中放置了View所有元素,並且在其中有另一個ImageView ,當以前的元素沒有填充屏幕(通常是大屏幕)時,它將其設置在屏幕底部,並設置為存在Scroll時ScrollView的底部。

我可以進行其他一些Activities ,但是在一個具有FrameLayout Activity中有一些問題。

我得到的是:

(請參見下面的代碼)當我在ImageViewRelativeLayout中設置(留在底部的那個) height = "wrap_content"

  • 縱向放置: Image沒有實際大小,因為它不適合屏幕顯示。 為了適合它,應該出現Scroll ->我不知道為什么它不像其他Activities中那樣出現。
  • 橫向放置: ImageView出現在屏幕底部。 由於其他元素無法顯示在屏幕上,因此Scroll出現在FrameLayout

當我在ImageViewRelativeLayout中設置(留在底部的那個) height = "200dp" (圖像的實際高度較小)時:

  • 縱向放置: Image不出現。 沒有任何Scroll (這是不必要的,因為可以看到其他元素)。
  • 橫向放置:出現兩個Scrolls 一個在FrameLayout內部用於元素,另一個用於查看ImageView

這是我最新的代碼:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    tools:context=".FacturasActivity"
    android:orientation="vertical" >

    <LinearLayout 
        android:id="@+id/linearLayoutLogoFactor_factura"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal" >

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

    </LinearLayout>

    <ScrollView
        android:id="@+id/scrollViewMain"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:fillViewport="true" >

        <LinearLayout
            android:id="@+id/linearLayoutMain2"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_gravity="center_horizontal"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:orientation="vertical" >

            <LinearLayout 
                android:id="@+id/linearLayoutDireccionFactura"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="25dp"
                android:layout_marginRight="25dp"
                android:layout_marginTop="10dp"
                android:weightSum="1.0">

                <TextView
                    android:id="@+id/textViewlabelDireccionFactura"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.3"
                    android:text="@string/etiqueta_direccion"
                    android:textSize="@dimen/textSize"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/textViewDireccion"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.7"
                    android:textSize="@dimen/textSize" />

            </LinearLayout>

            <FrameLayout
                android:id="@+id/frameLayoutFacturas"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="25dp"
                android:layout_marginRight="25dp"
                android:layout_marginTop="10dp" >

                <ListView
                    android:id="@android:id/list"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

                <TextView
                    android:id="@android:id/empty"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/facturas_vacia"
                    android:textSize="@dimen/textSize" />

            </FrameLayout>

            <RelativeLayout
                android:id="@+id/linearLayoutImagenInferior_main"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp" >

                <ImageView
                    android:id="@+id/imageViewImagenInferior_main"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:layout_centerHorizontal="true"
                    android:adjustViewBounds="true"
                    android:src="@drawable/la_electrica_de_las_empresas" />
            </RelativeLayout>

        </LinearLayout>

    </ScrollView>

</LinearLayout>

你能幫助我嗎? 提前致謝。

查看該問題 ,我發現的解決方案是:

創建該功能:

public static void setListViewHeightBasedOnChildren(ListView listView) {
        ListAdapter listAdapter = listView.getAdapter(); 
        if (listAdapter == null) {
            // pre-condition
            return;
        }

        int totalHeight = 0;
        for (int i = 0; i < listAdapter.getCount(); i++) {
            View listItem = listAdapter.getView(i, null, listView);
            listItem.measure(0, 0);
            totalHeight += listItem.getMeasuredHeight();
        }

        ViewGroup.LayoutParams params = listView.getLayoutParams();
        params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
        listView.setLayoutParams(params);
    }

並用我的ListView調用它。 只能看到和使用一個ScrollScrollView )。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM