[英]Android Image is seen/not seen when orientation is changed
I'm having some problems with ScrollView
and an ImageView
. 我在
ScrollView
和ImageView
遇到一些问题。
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"
: (请参见下面的代码)当我在
ImageView
的RelativeLayout
中设置(留在底部的那个) height = "wrap_content"
:
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
中那样出现。 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): 当我在
ImageView
的RelativeLayout
中设置(留在底部的那个) height = "200dp"
(图像的实际高度较小)时:
Image
doesn't appear. Image
不出现。 There isn't any Scroll
(it is not necessary because other elements are seen). Scroll
(这是不必要的,因为可以看到其他元素)。 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. 只能看到和使用一个
Scroll
( ScrollView
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.