我知道如何使用View.getRootView()获取根视图.我也能从一个按钮的onClick事件中获取视图,其中参数是一个视图.但是如何在活动中获取视图?
我被指派制作一个与Google地图显示找到结果的底页的行为类似的用户界面.
它有三个不同的阶段:
以下是我在Google地图上讨论的内容:
事实是,底页不是设计库的一部分(尽管这是请求的,这里).
不仅如此,UI似乎相当复杂,需要在多个阶段处理工具栏.
我已经找到了底部片(一个很好的(足够的)库在这里),并添加内容到它的碎片样本,有大致相同的看法材料设计的样品,如图(如这里),有一个CollapsingToolbarLayout会照顾阶段2 + 3.
在我正在制作的应用程序中,我还必须在滚动时移动一个图标,但我认为如果我成功完成其余部分,这应该很容易.这是代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_content"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="@dimen/detail_backdrop_height"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">
<ImageView
android:id="@+id/backdrop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="24dp">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/card_margin">
<LinearLayout
style="@style/Widget.CardContent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Info"
android:textAppearance="@style/TextAppearance.AppCompat.Title"/> …Run Code Online (Sandbox Code Playgroud) android material-design android-design-library android-coordinatorlayout android-collapsingtoolbarlayout
我可以使用adb connect连接到我的手机,我也可以adb shell.
但是当我去Run-> Device Chooser时,那里没有设备.
我该怎么做才能连接我的(连接的)adb Android Studio?
当我通过USB插入它时,它会显示在列表中
我希望我的项目GridView是正方形的.有2列,项目宽度为fill_parent(例如,它们占用尽可能多的水平空间.这些项目是自定义视图.
如何使项目高度等于其可变宽度?
我有一张来自网络的图片ImageView.它非常小(一个favicon),我想将它存储在我的SQLite数据库中.我可以得到一个Drawable,mImageView.getDrawable()但后来我不知道该怎么做.我不完全理解DrawableAndroid中的类.
我知道我可以从Bitmap类似的方式获得一个字节数组:
Bitmap defaultIcon = BitmapFactory.decodeStream(in);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
defaultIcon.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] bitmapdata = stream.toByteArray();
Run Code Online (Sandbox Code Playgroud)
但是如何从一个字节数组中获取Drawable?
升级到最新支持库'28.0.0-alpha1 '后,我无法禁用我的移位模式,BottomNavigationView即该BottomNavigationItemView.setShiftingMode()方法不再可用.
java.lang.NoSuchFieldException: No field mShiftingMode in class Landroid/support/design/internal/BottomNavigationMenuView;
W/System.err: at java.lang.Class.getDeclaredField(Native Method)
at com.avocure.avocurehealth.utils.ViewUtils.removeNavigationShiftMode(ViewUtils.java:44)
at com.avocure.avocurehealth.ui.main.MainActivity.init(MainActivity.java:125)
at com.avocure.avocurehealth.ui.main.MainActivity.onCreate(MainActivity.java:107)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Run Code Online (Sandbox Code Playgroud)
我使用此方法禁用换档模式.
如果有人能够了解最新版本中的某些内容是否发生了变化,或者这是一个错误还是其他什么,我们将非常感激.
我有RecyclerView一堆自定义视图,可能会在一段时间后改变高度,因为它们包含ImageView以异步方式加载图像的s.在RecyclerView没有拿起这个布局的变化,虽然我叫forceLayout上ImageView,并RecyclerView与初始化setHasFixedSize(false).ImageView已设置的所有容器父母android:layout_height="wrap_content".
如何RecyclerView更新其布局?好的,ListView这不是问题.
我正在尝试登录应用程序,但登录成功后即将进入下一个屏幕,它会重新启动.以下是我认为会引起这种情况的例外,因为没有其他例外.
11-14 15:09:54.841: W/WindowManager(643): Failed looking up window
11-14 15:09:54.841: W/WindowManager(643): java.lang.IllegalArgumentException: Requested window android.os.BinderProxy@4205eb18 does not exist
11-14 15:09:54.841: W/WindowManager(643): at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:7622)
11-14 15:09:54.841: W/WindowManager(643): at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:7613)
11-14 15:09:54.841: W/WindowManager(643): at com.android.server.wm.WindowState$DeathRecipient.binderDied(WindowState.java:1591)
11-14 15:09:54.841: W/WindowManager(643): at android.os.BinderProxy.sendDeathNotice(Binder.java:417)
11-14 15:09:54.841: W/WindowManager(643): at dalvik.system.NativeStart.run(Native Method)
11-14 15:09:54.841: I/WindowManager(643): WIN DEATH: null
Run Code Online (Sandbox Code Playgroud)
任何人都可以告诉,它是什么意思,如果可能的话,如何纠正它.
我尝试在ViewPager中使用CardView,每次我在CardView上向左/向右滑动它都会进入下一个屏幕.我想让卡片自己删除.目前作为一个独立的都工作正常,但当我结合时,只有viewpager工作,而不是cardwipe解雇.
我尝试使用下面的代码禁用ViewPager,但此代码也禁用了CardView滑动手势.我怎样才能让CardView有手势,当你在两张卡之间滑动时,它应该有ViewPager,因为它没有连接到卡元素.
或者完全禁用ViewPager并将其用作按钮并在CardView上启用滑动.我非常感谢任何帮助.提前致谢.
仅供参考:我在ViewPager中尝试过android_horizontal_listview,它运行正常,就像这样.
对于ViewPager:
mPager.setOnTouchListener(new OnTouchListener()
{
@Override
public boolean onTouch(View v, MotionEvent event)
{
return true;
}
});
Run Code Online (Sandbox Code Playgroud)
对于CardView:
SwipeableRecyclerViewTouchListener swipeTouchListener =
new SwipeableRecyclerViewTouchListener(mRecyclerView,
new SwipeableRecyclerViewTouchListener.SwipeListener() {
@Override
public boolean canSwipe(int position) {
return true;
}
@Override
public void onDismissedBySwipeLeft(RecyclerView recyclerView, int[] reverseSortedPositions) {
for (int position : reverseSortedPositions) {
mItems.remove(position);
mAdapter.notifyItemRemoved(position);
}
mAdapter.notifyDataSetChanged();
}
@Override
public void onDismissedBySwipeRight(RecyclerView recyclerView, int[] reverseSortedPositions) {
for (int position : reverseSortedPositions) {
mItems.remove(position);
mAdapter.notifyItemRemoved(position);
}
mAdapter.notifyDataSetChanged();
}
});
mRecyclerView.addOnItemTouchListener(swipeTouchListener);
Run Code Online (Sandbox Code Playgroud)
Mainactivity.java
public …Run Code Online (Sandbox Code Playgroud)