简体   繁体   English

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

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

I'm having some problems with ScrollView and an ImageView . 我在ScrollViewImageView遇到一些问题。

What I want is: 我想要的是:

I have an ImageView set always at the top of the screen. 我总是在屏幕顶部设置ImageView Then, I have an ScrollView where go all elements of the View , and inside it I have another ImageView which it is set at the bottom of the screen when previous elements don't fill screen (usually Big Screens), and it is set at the bottom of the ScrollView when exists Scroll. 然后,我有一个ScrollView ,其中放置了View所有元素,并且在其中有另一个ImageView ,当以前的元素没有填充屏幕(通常是大屏幕)时,它将其设置在屏幕底部,并设置为存在Scroll时ScrollView的底部。

It is ok for some other Activities I have, but I have some problems in one Activity that has a FrameLayout . 我可以进行其他一些Activities ,但是在一个具有FrameLayout Activity中有一些问题。

What I get is: 我得到的是:

(See code below) When I set in the RelativeLayout of the ImageView (the one to stay at the bottom) height = "wrap_content" : (请参见下面的代码)当我在ImageViewRelativeLayout中设置(留在底部的那个) height = "wrap_content"

  • In portrait orientation: The Image don't have its real size because it doesn't fit on the screen. 纵向放置: Image没有实际大小,因为它不适合屏幕显示。 To fit in it, Scroll should appear. 为了适合它,应该出现Scroll -> I don't know why it doesn't appear like in other Activities . ->我不知道为什么它不像其他Activities中那样出现。
  • In landscape orientation: ImageView appears at the bottom of the screen. 横向放置: ImageView出现在屏幕底部。 As other elements don't fit on the screen, Scroll appears inside FrameLayout . 由于其他元素无法显示在屏幕上,因此Scroll出现在FrameLayout

When I set in the RelativeLayout of the ImageView (the one to stay at the bottom) height = "200dp" (real height of image is smaller): 当我在ImageViewRelativeLayout中设置(留在底部的那个) height = "200dp" (图像的实际高度较小)时:

  • In portrait orientation: The Image doesn't appear. 纵向放置: Image不出现。 There isn't any Scroll (it is not necessary because other elements are seen). 没有任何Scroll (这是不必要的,因为可以看到其他元素)。
  • In landscape orientation: Appear two Scrolls . 横向放置:出现两个Scrolls One inside FrameLayout for elements, and another for seeing the ImageView . 一个在FrameLayout内部用于元素,另一个用于查看ImageView

Here is my code up to date: 这是我最新的代码:

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

Can you help me? 你能帮助我吗? Thanks in advance. 提前致谢。

The solution I've found, looking at that question , is: 查看该问题 ,我发现的解决方案是:

Create that function: 创建该功能:

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);
    }

and call it with my ListView. 并用我的ListView调用它。 Only one Scroll (the one of ScrollView ) is seen and used. 只能看到和使用一个ScrollScrollView )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 除非更改名称,否则无法看到图像 - Image can't be seen unless the name is changed 未看到 SVG 标签图像 Android webview - SVG tag image not seen Android webview 在spinner for android中看不到setOnItemSelectedListener - setOnItemSelectedListener is not seen in spinner for android 在网格布局的图像布局中看不到Android Studio NO图像 - Android Studio NO image is Seen in Image-Layout over Grid Layout FragmentActivity在方向更改时崩溃(MainActivity被视为Fragment) - FragmentActivity crashing on orientation change (MainActivity seen as Fragment) 当我运行应用程序时,在Android中看不到“固定选项卡” - My Fixed Tabs are not seen in android when i run app 在android studio中使用ScrollView时看到的其余布局 - Seen the rest of the layout when using the ScrollView in android studio 即使在 xml 中定义,也看不到 Android ActionBar 和 Toolbar - Android ActionBar and Toolbar are not seen even when defined in xml 手机复选框上显示为深色,但在android studio中看到时确定 - Dark Color Appreared on checkbox on phone but ok when seen in android studio 当我在 19 API 画廊中打开我的图片库时没有看到,但在 23API 中它显示画廊在 android studio 中? - when i open my image gallery in 19 API gallery is not seen but in 23API It shows gallery In android studio?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM