小编bor*_*str的帖子

找到可移动SD卡的位置

是否有通用的方法来查找外部SD卡的位置?

请不要与外部存储混淆.Environment.getExternalStorageState()返回内部SD挂载点的路径,如"/ mnt/sdcard".但问题是关于外部SD.如何获得像"/ mnt/sdcard/external_sd"这样的路径(它可能因设备而异)?

我想我将以mount文件系统名称过滤命令结束.但我不确定这种方式是否足够强大.

android external sd-card

199
推荐指数
11
解决办法
25万
查看次数

一个让GONE动画有效的简单方法

我有一个自定义搜索面板,这是主要布局的一部分.大多数时候面板都是隐藏的.我想在面板中添加出现/消失的动画.这是简化的布局摘录:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <RelativeLayout
        android:id="@+id/layoutSearch"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:visibility="gone" >
        <EditText
            android:id="@+id/editSearch"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <<Other inner views to be animated>>
    </RelativeLayout>
    <<Other views, which should not be affected by the animation>>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

尝试1:我添加了动画资源并使用XML中的这一行将它们附加到@ id/layoutSearch:

android:layoutAnimation="@anim/search_in_layout"
Run Code Online (Sandbox Code Playgroud)

动画/ search_in.xml:

<translate
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/overshoot_interpolator"
    android:fromYDelta="-100%p"
    android:toYDelta="0"
    android:duration="@android:integer/config_longAnimTime" />
Run Code Online (Sandbox Code Playgroud)

动画/ search_in_layout.xml:

<layoutAnimation
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:animation="@anim/search_in" />
Run Code Online (Sandbox Code Playgroud)

动画效果很好,但仅适用于出现的面板.当我隐藏它时,面板会在没有动画的情况下消失:

mSearchLayout.setVisibility(View.GONE);
Run Code Online (Sandbox Code Playgroud)

尝试2:我猜上面的解决方案不起作用,因为动画目标参数与当前面板位置匹配.好的,我创建了两个动画资源:anim/search_out.xml和anim/search_out_layout.xml.唯一的区别是交换"fromYDelta"和"toYDelta"值并更新"android:animation"值.然后我在代码中加载资源并将它们设置为@ id/layoutSearch,如下所示:

LayoutAnimationController controller =
    AnimationUtils.loadLayoutAnimation(this, R.anim.search_out_layout);
mSearchLayout.setLayoutAnimation(controller);
Run Code Online (Sandbox Code Playgroud)

调用setLayoutAnimation()时触发"out"动画.在动画之后,搜索面板返回到它在"out"动画之前的屏幕上的原始位置.如果我尝试在setLayoutAnimation()之后调用mSearchLayout.setVisibility(View.GONE),我看不到动画,面板立即消失.

尝试3:我想我需要在代码中创建动画,然后在其上设置一个监听器.然后我应该在onAnimationEnd()处理程序中调用mSearchLayout.setVisibility(View.GONE)以在播放动画后隐藏面板.我还没试过这个.我认为这太复杂了.

我想我错过了一些重要的事情.有没有办法实现GONE动画有点容易?

animation android

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

android ×2

animation ×1

external ×1

sd-card ×1