Created
May 18, 2015 07:50
-
-
Save pskink/d7f0673b77fe8537b270 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.app.myapplication; | |
import android.content.Context; | |
import android.util.AttributeSet; | |
import android.view.View; | |
/* | |
res/layout/fsvt.xml test layout file: | |
<?xml version="1.0" encoding="utf-8"?> | |
<com.example.app.myapplication.FlexScrollViewTest | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<ImageView | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:id="@+id/image" | |
android:src="@drawable/ic_launcher" | |
/> | |
<TextView | |
android:layout_width="match_parent" | |
android:layout_height="100sp" | |
android:id="@+id/header" | |
android:textSize="32sp" | |
android:text="drag/swipe anywhere up and down" | |
android:gravity="center" | |
android:background="#af00" | |
/> | |
<TextView | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:id="@+id/content" | |
android:textSize="32sp" | |
android:text="32\n31\n30\n29\n28\n27\n26\n25\n24\n23\n22\n21\n20\n19\n18\n17\n16\n15\n14\n13\n12\n11\n10\n9\n8\n7\n6\n5\n4\n3\n2\n1" | |
android:background="#a00f" | |
/> | |
</com.example.app.myapplication.FlexScrollViewTest> | |
*/ | |
public class FlexScrollViewTest extends FlexScrollView { | |
private static final String TAG = "FlexScrollViewTest"; | |
private View image; | |
private View header; | |
private View content; | |
public FlexScrollViewTest(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
} | |
@Override | |
protected void onFinishInflate() { | |
image = findViewById(R.id.image); | |
header = findViewById(R.id.header); | |
content = findViewById(R.id.content); | |
} | |
@Override | |
public int getMaxHeight() { | |
int w = MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.EXACTLY); | |
int h = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); | |
content.measure(w, h); | |
return getMeasuredHeight() + content.getMeasuredHeight(); | |
} | |
@Override | |
public void layoutChildren(int yOffset, int yDelta) { | |
// Log.d(TAG, "layoutChild " + yOffset + " " + yDelta); | |
int w = getWidth(); | |
int h = getHeight(); | |
int hh = header.getMeasuredHeight(); | |
int y1, y2; | |
if (yOffset < h - hh) { | |
y1 = h - yOffset - hh; | |
y2 = y1 + hh; | |
image.layout(0, -yOffset / 3, w, y1 + yOffset / 3); | |
image.setAlpha(1 - yOffset / (float) (h - hh)); | |
header.layout(0, y1, w, y2); | |
content.layout(0, y2, w, h); | |
content.scrollTo(0, 0); | |
} else { | |
y1 = 0; | |
y2 = hh; | |
image.layout(0, 0, 0, y1); | |
header.layout(0, y1, w, y2); | |
content.layout(0, y2, w, h); | |
content.scrollTo(0, yOffset - (h - hh)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Exception raised during rendering: com.android.layoutlib.bridge.MockView cannot be cast to android.view.ViewGroup