简体   繁体   English

setvisibility(view.oneible)在setvisibility之后无效(view.gone)

[英]setvisibility(view.visible) not working after setvisibility(view.gone)

I saw some post about this and I understood the problem. 我看到一些关于这个的帖子,我理解了这个问题。 But how can go around it? 但怎么能绕过它呢? I have ListView with item that can be expanded but once the view is gone it cannot be visible again, unless it has a free space. 我有ListView可以扩展的项目,但一旦视图消失,它再也看不到,除非它有一个空闲空间。 How to make that space? 如何制作那个空间?

private void mySetOnItemListener() {
    l.setOnItemClickListener(new OnItemClickListener() {

    @Override
    public void onItemClick(AdapterView<?> arg0, View view,
            int position, long arg3) {
        Log.d("onItemClick","called");
        LinearLayout ll = (LinearLayout)view.findViewById(R.id.llOpenedField);
        ll.setVisibility(View.VISIBLE);
    }
    });
}

my viewLayout 我的viewLayout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" 
    android:descendantFocusability="blocksDescendants">

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:orientation="horizontal"
        android:weightSum="5" >

        <TextView
            android:id="@+id/tv_name"
            android:layout_width="0px"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="4"
            android:padding="7dp"
            android:text="item"
            android:textColor="@android:color/background_dark"
            android:textSize="25dp" />
    </LinearLayout>

      <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/llOpenedField"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:orientation="horizontal"

         >

        <ImageButton
            android:id="@+id/ibInformation"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:src="@drawable/info" />

    </LinearLayout>

</LinearLayout>

the LinearLayout android:id="@+id/llOpenedField" is what im trying to make gone at start . LinearLayout android:id="@+id/llOpenedField"是我试图在开始时gone的东西。

i put the gone attribute in the getView() inside BaseAdapter . 我把gone属性在getView()BaseAdapter

If you put the code making an element visible into its onClickListener, it won't be reachable (if it consumes none of the screen-space, you won't be able to click on it). 如果将构成元素的代码放入其onClickListener中,则无法访问它(如果它不占用任何屏幕空间,则无法单击它)。 You should put a layout with a minimal height below it, and when your view l becomes gone, the new layout shell become visible, and it should get the visible-making onClickListener. 您应该在其下方放置一个最小高度的布局,当您的视图l消失时,新的布局shell将变为可见,并且它应该获得可见的onClickListener。 This way, after your View becomes gone, this new layout will be able to bring it back. 这样,在您的View消失后,这个新布局将能够将其恢复。

please check this answer. 请检查这个答案。 This answer work for me. 这个答案对我有用。

TranslateAnimation translateAnimation = new TranslateAnimation(0, 50, 0, 0);
          int animationTime = 200;
          translateAnimation.setDuration(animationTime);
          translateAnimation.setFillEnabled(true);
          translateAnimation.setFillAfter(true);
          yourView.startAnimation(translateAnimation);
          yourView.setVisibility(View.VISIBLE);

try this and modify according to your need ,this is not list item on which i am clicking 尝试这个并根据您的需要进行修改,这不是我点击的列表项

Make Linear layout android:visibility="gone" ; 使线性布局android:visibility="gone" ; first and do this this. 首先,这样做。

@Override
    public void onClick(View v)
    {
        LinearLayout ll = (LinearLayout)findViewById(R.id.vis);

        if(v == ex)
        {
            if(ll.getVisibility() == View.VISIBLE)
                ll.setVisibility(View.GONE);
            else
                ll.setVisibility(View.VISIBLE);
        }

update :- These are lines for you.. which will make proper expand and collapse ,and no free space will be there 更新: - 这些是你的线..这将使适当的扩展和崩溃,并没有自由空间

if(ll.getVisibility() == View.VISIBLE)
                    ll.setVisibility(View.GONE);
                else
                    ll.setVisibility(View.VISIBLE);

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

相关问题 在view.setVisibility(View.GONE)和view.setVisibility(View.VISIBLE)之后刷新RelativeLayout - RelativeLayout refresh after view.setVisibility(View.GONE) and view.setVisibility(View.VISIBLE) 从 View.GONE 状态到 View.VISIBLE 的 setVisibility 无法正常工作 - setVisibility from View.GONE state to View.VISIBLE not working properly setVisibility(View.GONE)不适用于textview - setVisibility(View.GONE) not working for textview setVisibility(View.GONE) 不起作用? 为什么? - setVisibility(View.GONE) is not working! Why? setVisibility(View.VISIBLE)到imageView不起作用 - setVisibility(View.VISIBLE) to imageView is not working Android setVisibility(View.Visible)不适用于布局 - Android setVisibility(View.Visible) not working on a layout 如何从 View.gone 恢复视图。 在 xml 中使用 'android:visibility="gone"' 后 setVisibility(View.VISIBLE) 不工作 - How to recover view from View.gone. setVisibility(View.VISIBLE) not working after using 'android:visibility="gone"' in xml 设置为不可见后,setVisibility(View.Visible)不起作用 - setVisibility(View.Visible) not working after setting to invisible 带有SwipeyTabs的setVisibility(View.Gone) - setVisibility(View.Gone) with SwipeyTabs Android BottomSheetDialogFragment 在视图 setVisibility(View.GONE) 后弹出到顶部 - Android BottomSheetDialogFragment popped to TOP after view setVisibility(View.GONE)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM