The last item in the scroll view requiring a double click to launch

I know this is similar to other problems, but since I find this to be quite peculiar behavior, I hope someone explains what is happening. WHY .

This is mainly a known click issue that needs to be double-clicked before running the code onClick

.
The cryptic bit is that this only happens inside ONE of many instances of the same nested layout.
We'll see...

I have the following main layout:

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

<ImageView
    android:id="@+id/imgBanner"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight=".80"
    android:src="@drawable/banner" />

<ScrollView
    android:id="@+id/scroll"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight=".20" >

    <LinearLayout
        android:id="@+id/panContent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/txtMainTitle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="xxx" />

        <TextView
            android:id="@+id/txtMainSubtitle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="xxx" />

    </LinearLayout>

</ScrollView>

</LinearLayout>

      

So, banner + scrolling with title + subtitle.
In this scroll, I want to insert some entries formatted in the following layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="match_parent" >

<TextView
    android:id="@+id/txtTitle"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true" />

<TextView
    android:id="@+id/txtSynopsis"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/btnAction"
    android:layout_below="@+id/txtTitle"
    android:layout_toRightOf="@+id/imgCover" />

<ImageView
    android:id="@+id/imgCover"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/txtTitle" />

<Button
    android:id="@+id/btnAction"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/imgCover"
    android:layout_alignRight="@+id/imgCover"
    android:layout_below="@+id/imgCover"
    android:text="Download" />

<ImageView
    android:id="@+id/imgFade"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/txtSynopsis"
    android:layout_alignLeft="@+id/txtSynopsis"
    android:layout_alignRight="@+id/txtSynopsis"
    android:scaleType="fitXY"
    android:src="@drawable/fade_down" />

<ImageView
    android:id="@+id/imgMore"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/imgFade"
    android:layout_alignLeft="@+id/imgFade"
    android:layout_alignRight="@+id/imgFade"
    android:onClick="showMore"
    android:src="@drawable/show_more" />

<ImageView
    android:id="@+id/imgLess"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/imgFade"
    android:layout_alignRight="@+id/imgFade"
    android:layout_below="@+id/txtSynopsis"
    android:layout_marginTop="-12dip"
    android:onClick="showLess"
    android:src="@drawable/show_less"
    android:visibility="gone" />

</RelativeLayout>

      

What will happen:

  • at the top
  • left: book cover + download button (below it)
  • right: synopsis, cut at the bottom of the download button, with the image to fade in the background (imgFade) and a show more button (plus a show less button that remains hidden)

In the method, onCreate

I add some content to the element panContent

, this way:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    LinearLayout panContent = (LinearLayout) findViewById(R.id.panContent);
    for (EntryModel m : this.entries) {
        ViewGroup g = new LinearLayout(this);
        getLayoutInflater().inflate(R.layout.entry, g);
        /* ... populating data in the TextView and ImageView ... */
        panContent.addView(g);
    }
}

      

Finally, here are the handlers onClick

:

public void showMore(View v) {
    RelativeLayout container = (RelativeLayout) v.getParent();

    View txt = container.findViewById(R.id.txtSynopsis);
    RelativeLayout.LayoutParams sLayout =
        (RelativeLayout.LayoutParams) txt.getLayoutParams();
    sLayout.addRule(RelativeLayout.ALIGN_BOTTOM, 0);

    container.findViewById(R.id.imgFade).setVisibility(View.GONE);
    container.findViewById(R.id.imgLess).setVisibility(View.VISIBLE);
    v.setVisibility(View.GONE);

    txt.setLayoutParams(sLayout);
}

public void showLess(View v) {
    RelativeLayout container = (RelativeLayout) v.getParent();

    View txt = container.findViewById(R.id.txtSynopsis);
    RelativeLayout.LayoutParams sLayout =
        (RelativeLayout.LayoutParams) txt.getLayoutParams();
    sLayout.addRule(RelativeLayout.ALIGN_BOTTOM, R.id.btnAction);

    container.findViewById(R.id.imgFade).setVisibility(View.VISIBLE);
    container.findViewById(R.id.imgMore).setVisibility(View.VISIBLE);
    v.setVisibility(View.GONE);

    txt.setLayoutParams(sLayout);
}

      

Basically:

  • when I click the "show more" image, untie txtSynopsis

    "from the bottom (so that it spans the number of lines it wants), hide the image (and the fading mask) and show the" show less "image;
  • when you click show less, well, restore things.

Here we go. This works flawlessly (almost ...) for EVERY ONE INPUT, but LAST !!!

What's going on with this:

  • I need to hit "TWICE" on "show more" for it to work,
  • I need to press "TWICE" to "show less"
  • then it is enough to click only once on "show more", but
  • I still need to hit "TWICE" on "show less"!

Thanks everyone, any help and helpful insight was greatly appreciated.

+3


source to share


1 answer


Make sure your view isn't in focus



0


source







All Articles