У меня есть экран приложения, где у меня есть веб-просмотр, и линейная компоновка кнопок внизу экрана. У меня есть прослушиватель прокрутки, прикрепленный к webview, который дает мне значения при прокрутке. То, что я действительно хочу сделать, постепенно скрывает нижний линейный макет при прокрутке вниз и показывает при прокрутке вверх, как видно из нескольких небольших приложений, но все примеры, которые я вижу, - это панели инструментов в верхней части экрана.Скрыть linearlayout на прокрутке webview
Я пробовал несколько вещей, я попытался получить высоту линейного макета, а затем прокрутить, переместить его по оси y, чтобы скрыть и показать, и это перемещало кнопки внутри, но не фактический бар ,
Главное, что я пробовал, - это прокрутка, уменьшение высоты бара, а при достижении 0 - скрытие его, а затем его повторное отображение, но это раздавливание кнопок, а не прокрутка их в нижней части экрана без изменения их размера.
Это расположение:
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:id="@+id/buttonBar"
android:background="#403152"
android:visibility="gone"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/facebookLink"
android:src="@string/button1"
android:layout_weight="1"
android:onClick="openLink"
android:background="@android:color/transparent"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/linkedinLink"
android:src="@string/button2"
android:layout_weight="1"
android:background="?android:selectableItemBackground"
android:onClick="openLink"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/twitterLink"
android:src="@string/button3"
android:layout_weight="1"
android:background="?android:selectableItemBackground"
android:onClick="openLink"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/instagramLink"
android:src="@string/button4"
android:layout_weight="1"
android:background="?android:selectableItemBackground"
android:onClick="openLink"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@mipmap/ic_overflow"
android:layout_weight="1"
android:layout_gravity="center"
android:background="?android:selectableItemBackground"
android:onClick="showPopup"
android:id="@+id/aboutoption"/>
</LinearLayout>
<holidays.ObservableWebView
android:id="@+id/scrollableWebview"
android:layout_width="fill_parent"
android:clickable="false"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_above="@id/buttonBar"
android:visibility="gone"/>
, а затем это код, который я пытался до сих пор, который включает в себя изменения высоты, и т.д. - Надеясь кто-то может быть в состоянии указать меня в правильном направлении, что Я делаю неправильно, или что может быть лучшим способом справиться с этим.
mWebView.setOnScrollChangedCallback(new ObservableWebView.OnScrollChangedCallback(){
public void onScroll(int l, int t){
int height = mWebView.getMeasuredHeight();
Log.d("HEIGHT", Integer.toString(height));
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int screenHeight = size.y;
Log.d("Screen HEIGHT", Integer.toString(screenHeight));
LinearLayout layout = (LinearLayout)findViewById(R.id.buttonBar);
View contentsView = findViewById(R.id.buttonBar);
if(firstScroll == true){
mWebView.setLayoutParams(new RelativeLayout.LayoutParams(mWebView.getMeasuredWidth(), mWebView.getMeasuredHeight() + 10));
/*originalButtonBarHeight = findViewById(R.id.buttonBar).getHeight();
currentButtonBarHeight = originalButtonBarHeight;
contentsView.getLocationOnScreen(screenBarPosition);
contentsView.setY(screenBarPosition[1] + 1);
firstScroll = false;
layout.getLayoutParams().height = t + 1;
layout.requestLayout();
directionVal = t;*/
}
else if(firstScroll == false){
if(directionVal < t){
mWebView.setLayoutParams(new RelativeLayout.LayoutParams(mWebView.getMeasuredWidth(), mWebView.getMeasuredHeight() + 10));
/* Log.d("DOWN", Integer.toString(t));
if(currentButtonBarHeight <= 0){
//do nothing
}
else{
currentButtonBarHeight = currentButtonBarHeight - 5;
if(currentButtonBarHeight <= 0){
currentButtonBarHeight = 0;
layout.getLayoutParams().height = 0;
layout.requestLayout();
findViewById(R.id.buttonBar).setVisibility(View.GONE);
}
else{
contentsView.getLocationOnScreen(screenBarPosition);
contentsView.setY(screenBarPosition[1] + 1);
layout.getLayoutParams().height = currentButtonBarHeight;
layout.requestLayout();
}
}
/*if(t + 5 < originalButtonBarHeight) {
}*/
}
else if(directionVal > t){
Log.d("UP", Integer.toString(currentButtonBarHeight));
/*decreasedAmount = t - 5;
if (decreasedAmount < originalButtonBarHeight){
layout.getLayoutParams().height = t - 5;
layout.requestLayout();
}*/
}
directionVal = t;
}
}
});
Это только показывает/скрывает, а не постепенно показывает/скрывает? – Navvy