【问题标题】:Images in Android ActionBar Spinner are LargeAndroid ActionBar Spinner 中的图像很大
【发布时间】:2014-03-11 15:16:25
【问题描述】:

我的 Android 操作栏中有一个图像微调器,但是当我单击它时,图像并没有按比例缩小。这是我的应用程序的截图:

这是我的微调器布局代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageView
        android:id="@+id/icon"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerInside" >
    </ImageView>

</LinearLayout>

这是 menu.xml 中的项目声明:

<item
    android:id="@+id/menu_spinner"
    android:actionViewClass="android.widget.Spinner"
    android:showAsAction="ifRoom"
    android:title="Share"/>

【问题讨论】:

    标签: android xml android-layout spinner android-menu


    【解决方案1】:

    android:layout_widthandroid:layout_height 中都使用wrap_content 而不是match_parent 来表示ImageView,如下所示...

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
        <ImageView
            android:id="@+id/icon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:scaleType="centerInside" >
        </ImageView>
    
    </LinearLayout>
    

    【讨论】:

    • 我尝试了这个解决方案,但它没有改变任何东西。 “分享”按钮的大小仍然相同。
    • 您可以将LinearLayout的大小固定为100dip,然后将match_parent设置为ImageView
    【解决方案2】:

    也许有人可以给出一个全面的答案,但您需要对屏幕 dpi 使用资源过滤。

    例如“drawable-mdpi”、“drawable-hdpi”

    只需在文件夹中放置适当(缩放的)尺寸

    编辑:

    好吧,我尝试了类似的布局

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#ffff920f">
    
        <ImageView
            android:id="@+id/main_spinner_item_imageview"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/abc_ic_cab_done_holo_light"
            android:scaleType="fitCenter"/>
    
    </FrameLayout>
    

    在一个示例项目中,一切正常。正如我之前提到的,您需要为屏幕 dpi 缩放图标。下面有一个文件夹-大小列表

    • “drawable-mdpi”,32x32
    • “drawable-hdpi”,48x48
    • “drawable-xhdpi”,72x72
    • “drawable-xxhdpi”,96x96

    更多示例,请参阅操作栏图标包here

    【讨论】:

    • 好的。有哪些不同的图标大小?你能指出一些有操作栏项目尺寸规格的地方吗?谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-09
    • 1970-01-01
    • 1970-01-01
    • 2012-03-05
    • 1970-01-01
    • 1970-01-01
    • 2017-07-31
    相关资源
    最近更新 更多