gpt4 book ai didi

android - 从 anchor 滑动到折叠状态时,Umano SlidingUpPanel 卡住

转载 作者:行者123 更新时间:2023-11-29 01:19:33 28 4
gpt4 key购买 nike

我创建了一个 SlidingUpPanel它由顶部布局中的谷歌地图和底部面板中的 ListView 组成。布局也有一个 anchor 。我遇到的问题是,很多时候当我将面板从 anchor 滑动到折叠状态时,它会卡在中间,这样我必须多次滑动才能从 anchor 移动到折叠状态。为什么会发生这种情况,我该如何解决?

xml

   <com.sothree.slidinguppanel.SlidingUpPanelLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:sothree="http://schemas.android.com/apk/res-auto"
android:id="@+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
sothree:umanoShadowHeight="0dp"
sothree:umanoScrollableView="@+id/rvOrderHistory"
sothree:umanoInitialState="anchored"
sothree:umanoPanelHeight="110dp"
sothree:umanoFadeColor="@android:color/transparent"
>
<!--xmlns:app="http://schemas.android.com/tools"-->
<RelativeLayout
android:id="@+id/maincontent_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical"
>
<RelativeLayout
android:id="@+id/maplayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<fragment
android:id="@+id/map"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageView
android:id="@+id/ren"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="80dp"
android:layout_marginRight="@dimen/ten_dp"
android:src="@drawable/ryuh" />
<include
layout="@layout/search_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

</RelativeLayout>
</RelativeLayout>
<LinearLayout
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical"
>

<ListView
android:id="@+id/uuygu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@drawable/line_divider"
android:drawSelectorOnTop="false"
android:fastScrollEnabled="false"
android:footerDividersEnabled="false"
android:headerDividersEnabled="false"
android:scrollbars="none" />
</LinearLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>

搜索布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:elevation="@dimen/five_dp">

<AutoCompleteTextView
android:id="@+id/address"
android:layout_width="match_parent"
android:layout_height="@dimen/fourty_dp"
android:layout_gravity="top"
android:elevation="@dimen/five_dp"
android:layout_margin="@dimen/ten_dp"
android:background="@color/white_transpirancey"
android:drawableRight="@drawable/search_icon"

android:padding="@dimen/ten_dp"
android:imeOptions="actionSearch"
android:singleLine="true"
android:textColor="@color/black"
android:textColorHint="@color/gray_variant_2"
android:textSize="@dimen/fifteen_sp" />

</LinearLayout>

代码

    @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mContext = getActivity();
View rootLayout = LayoutInflater.from(getActivity()).inflate(R.layout.ljg_fragment, null);

mSlidingLayout = (SlidingUpPanelLayout) rootLayout.findViewById(R.id.sliding_layout);

.
.
.
mSearchAdapter = new SearchAdapter(mContext);
mSlidingLayout.setAnchorPoint(0.4f);
mSlidingLayout.setDragView(mListLayout);
mSlidingLayout.setPanelState(SlidingUpPanelLayout.PanelState.ANCHORED);
height = mMapLayout.getHeight();
int screenSize = getResources().getConfiguration().screenLayout &
Configuration.SCREENLAYOUT_SIZE_MASK;
switch (screenSize) {
case Configuration.SCREENLAYOUT_SIZE_XLARGE:
mLargeScreen = true;
break;
case Configuration.SCREENLAYOUT_SIZE_LARGE:
mLargeScreen = true;
break;
case Configuration.SCREENLAYOUT_SIZE_NORMAL:
mLargeScreen = false;
break;
case Configuration.SCREENLAYOUT_SIZE_SMALL:
mLargeScreen = false;
break;
default:
mLargeScreen = false;
}

if (googleMap == null) {
googleMap = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
googleMap.getUiSettings().setCompassEnabled(false);
googleMap.setIndoorEnabled(false);
googleMap.getUiSettings().setMapToolbarEnabled(false);
}
mSlidingLayout.addPanelSlideListener(new SlidingUpPanelLayout.PanelSlideListener() {
@Override
public void onPanelSlide(View panel, float slideOffset) {

}
@Override
public void onPanelStateChanged(View panel, SlidingUpPanelLayout.PanelState previousState, SlidingUpPanelLayout.PanelState newState) {

if (newState == SlidingUpPanelLayout.PanelState.ANCHORED) {
googleMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(Double.parseDouble(AppPreferences.getLat(mContext)), Double.parseDouble(AppPreferences.getLong(mContext)))));
googleMap.animateCamera(CameraUpdateFactory.zoomTo(17), 2000, null);
refreshBtn.setPadding(0, 0, 10, refreshIconMargin);
} else if (newState == SlidingUpPanelLayout.PanelState.COLLAPSED) {
googleMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(Double.parseDouble(AppPreferences.getLat(mContext)), Double.parseDouble(AppPreferences.getLong(mContext)))));
googleMap.animateCamera(CameraUpdateFactory.zoomTo(16), 2000, null);
refreshBtn.setPadding(0, 0, 10, 10);
}
}
});
googleMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
...
}
});
googleMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {

....

}
});



searchtaxt.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN) {
InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(actvAddress.getWindowToken(), 0);
callXYZApi();
}
return false;
}
});



rvList.setOnScrollListener(new EndlessScrollListener() {
@Override
public boolean onLoadMore(int page, int totalItemsCount) {

callXYZApi();
}
return true; // ONLY if more data is actually being loaded; false otherwise.
}
});

return rootLayout;
}

根据Aman的回答贴出了从anchor到collapsed状态的日志-

06-21 11:39:40.604 1502-1502/TEST: onPanelStateChanged: prevoius state : ANCHORED  new state: DRAGGING
06-21 11:39:40.604 1502-1502/TEST: onPanelSlide: 0.3428332
06-21 11:39:40.620 1502-1502/TEST: onPanelSlide: 0.27158424
06-21 11:39:40.628 1502-1502/TEST: onPanelSlide: 0.25062868
06-21 11:39:40.637 1502-1502/TEST: onPanelSlide: 0.21961442
06-21 11:39:40.653 1502-1502/TEST: onPanelSlide: 0.16680637
06-21 11:39:40.670 1502-1502/TEST: onPanelSlide: 0.122380555
06-21 11:39:40.686 1502-1502/TEST: onPanelSlide: 0.08968986
06-21 11:39:40.702 1502-1502/TEST: onPanelSlide: 0.064543165
06-21 11:39:40.718 1502-1502/TEST: onPanelSlide: 0.04526404
06-21 11:39:40.735 1502-1502/TEST: onPanelSlide: 0.030176027
06-21 11:39:40.751 1502-1502/TEST: onPanelSlide: 0.020117352
06-21 11:39:40.767 1502-1502/TEST: onPanelSlide: 0.012573345
06-21 11:39:40.783 1502-1502/TEST: onPanelSlide: 0.0075440067
06-21 11:39:40.800 1502-1502/TEST: onPanelSlide: 0.004191115
06-21 11:39:40.816 1502-1502/TEST: onPanelSlide: 0.002514669
06-21 11:39:40.832 1502-1502/TEST: onPanelSlide: 8.38223E-4
06-21 11:39:40.865 1502-1502/TEST: onPanelSlide: 0.0
06-21 11:39:40.883 1502-1502/TEST: onPanelStateChanged: prevoius state : DRAGGING new state: COLLAPSED

卡住时记录

onPanelStateChanged: prevoius state : ANCHORED  new state: DRAGGING
06-21 11:48:54.909 7299-7299/TEST: onPanelSlide: 1.0
06-21 11:48:54.909 7299-7299/TEST: onPanelSlide: 0.30511317
06-21 11:48:54.928 7299-7299/TEST: onPanelStateChanged: prevoius state : DRAGGING new state: ANCHORED

最佳答案

我已经尝试过,并且 slidinguppanellayout 正在按照您希望的代码工作。但是,如果您仍然无法获得所需的结果,那么您可以添加一个 PanelSlideListener 并像我一样实现它的方法。

public class MainActivity extends AppCompatActivity {

private static final String TAG = "MainActivity";
private LinearLayout mListLayout;
private SlidingUpPanelLayout mSlidingLayout;
float slideoffset=1;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mListLayout = (LinearLayout) findViewById(R.id.main_layout);
mSlidingLayout = (SlidingUpPanelLayout) findViewById(R.id.sliding_layout);
mSlidingLayout.setAnchorPoint(0.4f);
mSlidingLayout.setDragView(mListLayout);
mSlidingLayout.addPanelSlideListener(new SlidingUpPanelLayout.PanelSlideListener() {
@Override
public void onPanelSlide(View panel, float slideOffset) {
slideoffset=slideOffset;
Log.d(TAG, "onPanelSlide: " + slideOffset);
}

@Override
public void onPanelStateChanged(View panel, SlidingUpPanelLayout.PanelState previousState, SlidingUpPanelLayout.PanelState newState) {
Log.d(TAG, "onPanelStateChanged: prevoius state : " + previousState + " new state: " + newState);
if(slideoffset<0.2&&(previousState== SlidingUpPanelLayout.PanelState.ANCHORED||previousState== SlidingUpPanelLayout.PanelState.EXPANDED))
{
mSlidingLayout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
}

}
});
}

}

首先,我从 onPanelSlide 方法获取 slidingOffset 并使用此 slidingOffset 值来确定 slidinguppanellayout 的当前位置,以便在 onPanelStateChanged 方法中我可以使用先前的状态和 slideOffset 值来了解设置的结束状态。

If you still persist problem after this then just post out the logcat.

关于android - 从 anchor 滑动到折叠状态时,Umano SlidingUpPanel 卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37765192/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com