我创建了一个SlidingUpPanel,其中顶层布局中的谷歌地图和底部面板中的列表视图。布局也有一个锚点。我遇到的问题是我多次滑动面板从锚点到倒塌的状态它介于两者之间,我必须多次滑动以从锚定状态转变为崩溃状态。为什么会发生这种情况,我该如何解决这个问题?
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>
search_layout
<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的答案在从锚定状态转变为折叠状态时发布日志 -
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
答案 0 :(得分:1)
我已经尝试过,slideuppanellayout正如您所希望的那样从您的代码中运行。 但如果你仍然无法获得所需的结果,那么你可以添加一个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值来知道设置结束状态。
如果您在此之后仍然存在问题,那么只需发布logcat。
答案 1 :(得分:0)
以下代码适用于我。希望这会有所帮助。
@Override
public void onPanelSlide(View panel, float slideOffset) {
slideoffset=slideOffset;
}
@Override
public void onPanelStateChanged(View panel, SlidingUpPanelLayout.PanelState previousState, SlidingUpPanelLayout.PanelState newState)
{
if(slideoffset<0.2&& previousState == SlidingUpPanelLayout.PanelState.DRAGGING)
{
mLayout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
}
else if(slideoffset == 1&& previousState == SlidingUpPanelLayout.PanelState.DRAGGING)
{
mLayout.setPanelState(SlidingUpPanelLayout.PanelState.EXPANDED);
}}