Мой ответ не является ни самым надёжным, ни самым простым. Но я считаю, что можно обойтись и базовыми возможностями.
Что можно:
- Не пытаться оставить те же самые кнопки на месте
Создайте одинаковые модели кнопок: одни будут внутри ScrollView, другие - поверх него (FrameLayout или RelativeLayout)
Прятать одни и показывать другие
Так как выше кнопок внутри ScrollView есть ещё один элемент, используйте его для определения полной видимости кнопок. Если шапка видна - спрячьте кнопки, находящиеся выше, и покажите основные
Оставлю код и макет примерной работы (готовую работу, возможно, отправлю позже, а эта показывает только логику, принцип):
import android.app.Activity;
import android.graphics.Rect;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
import android.view.ViewTreeObserver.OnScrollChangedListener;
public class MainActivity extends Activity {
ScrollView scrollView;
TextView textView1, textView2;
Toast toast;
Rect scrollBounds = new Rect();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
scrollView = (ScrollView) findViewById(R.id.scroll_view);
textView1 = (TextView) findViewById(R.id.text_view1);
textView2 = (TextView) findViewById(R.id.text_view2);
scrollView.getHitRect(scrollBounds);
toast = Toast.makeText(MainActivity.this, "TextView1 is visible", Toast.LENGTH_SHORT);
OnScrollChangedListener f = new OnScrollChangedListener() {
@Override
public void onScrollChanged() {
if (textView1.getLocalVisibleRect(scrollBounds)) {
toast.show();
} else {
};
};
};
scrollView.getViewTreeObserver().addOnScrollChangedListener(f);
};
}
Макет:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent" >
<ScrollView
android:id="@+id/scroll_view"
android:layout_height="match_parent"
android:layout_width="match_parent" >
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/text_view1"
android:text="text1"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
<TextView
android:id="@+id/text_view2"
android:textSize="50sp"
android:text="text2\nmpmcmoofmwpwpdmifnwpmfiefmovmwuwdhoekfrocmwicmepcmelfmeomormgormfofoefpmeoeoenfhfmfiegoencieomwpdmwomefmreicnofniefmenfwonceinfiecnemcenfoen"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
</LinearLayout >
</ScrollView >
</LinearLayout >