[英]setVisibility(View.VISIBLE) not working when element is not the last in LinearLayout
I'm updating my interface programmatically in order to show an ImageView inside my main menu. 我正在以编程方式更新我的界面,以便在主菜单中显示ImageView。 It works correctly when the ImageView is the last inside his parent (a LinearLayout). 当ImageView是其父项中的最后一个(LinearLayout)时,它可以正常工作。 But it doesn't work when it is the first item in Layout or is between some others elements. 但是当它是Layout中的第一项或位于其他元素之间时,它将不起作用。
This is my layout: 这是我的布局:
<FrameLayout 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:background="@android:color/black"
android:gravity="right"
tools:context=".Actualidad" >
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitStart"
android:src="@drawable/main_bg" />
<ScrollView
android:id="@+id/iSV_Botones_drc"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="5dp"
android:fillViewport="true" >
<LinearLayout
android:id="@+id/drc_menu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="right"
android:gravity="right"
android:orientation="vertical" >
<ImageView
android:id="@+id/iv_main_actualidad"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:maxWidth="9dp"
android:src="@drawable/btnmenuiconactualidad" />
<ImageView
android:id="@+id/iv_main_discos_giras"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:layout_marginTop="@dimen/menu_items_margin_top"
android:src="@drawable/btnmenuicondiscos"
android:visibility="gone" />
<ImageView
android:id="@+id/iv_main_espectaculos"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginTop="@dimen/menu_items_margin_top"
android:layout_weight="1"
android:src="@drawable/btnmenuiconeventos" />
</LinearLayout>
</ScrollView>
And this is the code where I set visible the ImageView (iv_main_discos_giras): 这是我将ImageView(iv_main_discos_giras)设置为可见的代码:
private Handler mResultHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
mDiscosGiras.setVisibility(View.VISIBLE);
Log.d(getClass().getSimpleName(), "Item visible!!");
}
};
Log is being shown correctly, and mDiscosGiras has been already initialized: 日志显示正确,并且mDiscosGiras已经初始化:
@InjectView(R.id.iv_main_discos_giras) ImageView mDiscosGiras; here
I've found a hack that is working very well. 我发现一个运行良好的黑客程序。
I simply make invisible all items below that item for a moment. 我只是暂时使该项目下面的所有项目不可见。 Then I set visibles all items, from top to bottom. 然后,我将所有项目从上到下设置为可见。
NOTE: This works also with android:animateLayoutChanges="true"
in LinearLayout, with a nice animation. 注意:这也android:animateLayoutChanges="true"
于LinearLayout中的android:animateLayoutChanges="true"
,动画效果不错。
private Handler mResultHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
mEspectaculos.setVisibility(View.GONE);
mDiscosGiras.setVisibility(View.VISIBLE);
mEspectaculos.setVisibility(View.VISIBLE);
Log.i(getClass().getSimpleName(), "Ponemos el tema visible");
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.