2016-04-07 64 views
2

我正在用Facebook编写Fresco图书馆的应用程序。壁画,如何缩放不同设备的图像

我有问题试图了解如何使用Fresco实现视图,如果我的应用程序可以在不同设备间使用。正如您在附件中看到的,我有一个Nexus6,一个NexusOne和一个Nexus7。

它们都有相同的Fresco Drawee(200dp x 200dp)。正如我读过Fresco的文档,有必要和必须修复图像大小。然而,我无法理解如何实现像使用Fresco使用50%图像宽度的ImageView一样简单的操作。

想要的结果是使图像使用一半的屏幕(宽度方面),并为不同的文本保留其余空间(显示标题+说明)。

通常情况下,我会用重量来做这个,但是我不知道如何用库来实现这个,或者最佳实践是什么。

基于this问题(和文档),我不确定是否添加侦听器是最佳选择。我只是无法理解Facebook或其他使用这个库的应用程序是如何为不同的设备做的。

预先感谢

Nexus One Nexus 6 enter image description here

此图像的显示的代码是基本上如下:

  <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:weightSum="10"> 

      <com.facebook.drawee.view.SimpleDraweeView 
       android:id="@+id/my_image_view" 
       android:layout_width="200dp" 
       android:layout_height="200dp" 

       fresco:actualImageScaleType="focusCrop" 
       fresco:backgroundImage="@drawable/user_icon" 
       fresco:fadeDuration="300" 
       fresco:placeholderImage="@color/common_action_bar_splitter" 
       fresco:placeholderImageScaleType="fitCenter" /> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="vertical" 
       android:layout_toRightOf="@+id/my_image_view"> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:textSize="20sp" 
        android:text="Title 1" /> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:textSize="15sp" 
        android:textColor="@color/menu_color" 
        android:text="Description 1" /> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:textSize="20sp" 
        android:text="Title 2" /> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:textSize="15sp" 
        android:textColor="@color/menu_color" 
        android:text="Description 2" /> 


      </LinearLayout> 


     </RelativeLayout> 

UPDATE:

我还d不知道如何获得全屏图像。如果我们必须指定维度,或者使用match_parent,但是在两者上使用match_parent都会使用整个父级,那么如何获得类似于显示Facebook图像的图像呢?

我相信@Gueorgui Obregon's是个好主意,但是我仍然想知道如果问题是使用50%的屏幕图片的设计模式。例如,拿两个尺寸相同的手机型号(例如MDPI),但其中一个比另一个宽一点。使用尺寸方法我会比在一个移动设备上占用一半的屏幕,但在另一个移动设备上,它需要多一点/少一点。

总结:问题在哪里?在设计视图时,是否认为百分比是一个坏主意?我应该告诉我的设计师,对于android来说,使用百分比是一个糟糕的设计理念吗?更重要的是,Facebook如何实现最后一张照片(图片使用大约33%的屏幕)?

Facebook Image

Image % on Facebook

+0

我的回答对您有帮助吗? –

回答

1

你可以使用dimensions.xml针对不同不同屏幕文件夹。

res/values/dimensions.xml 
res/values-sw600dp/dimensions.xml -> 7+ inches 
res/values-sw720dp/dimensions.xml -> 10+ inches 

添加在每个维度的愿望值

RES /值/ dimensions.xml

<dimen name="my_image_view_width">200dp</dimen> 
<dimen name="my_image_view_height">200dp</dimen> 

RES /值-sw720dp/dimensions.xml

<dimen name="my_image_view_width">400dp</dimen> 
<dimen name="my_image_view_height">400dp</dimen> 

然后只需使用@dimen/my_image_view_width@dimen/my_image_view_heightSimpleDraweeView这样

<com.facebook.drawee.view.SimpleDraweeView 
    android:id="@+id/my_image_view" 
    android:layout_width="@dimen/my_image_view_width" 
    android:layout_height="@dimen/my_image_view_height" 
    fresco:actualImageScaleType="focusCrop" 
    fresco:backgroundImage="@drawable/user_icon" 
    fresco:fadeDuration="300" 
    fresco:placeholderImage="@color/common_action_bar_splitter" 
    fresco:placeholderImageScaleType="fitCenter" /> 

希望这有助于!

+0

感谢您的回复Gueorgui,我已经更新了我的答案,因为我仍然有关于此方法的几个问题。我认为这肯定比在所有维度上使用固定的dp更好,但是我仍然怀疑这是否是最好的方法。 – Waclock