android studio预览版和手机版的区别
我有一个名为“neura_bar_img”的图像视图,右侧有两个文本视图: XML代码:android studio预览版和手机版的区别,android,xml,android-studio,Android,Xml,Android Studio,我有一个名为“neura_bar_img”的图像视图,右侧有两个文本视图: XML代码: <android.support.v7.widget.CardView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/summaryCard" android:layout_below="@+id/topCard" androi
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/summaryCard"
android:layout_below="@+id/topCard"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
app:layout_heightPercent="25%"
app:layout_marginTopPercent="3%"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="3dp"
android:paddingBottom="3dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true">
<ImageView
android:layout_width="270dp"
android:layout_height="113dp"
android:id="@+id/neura_bar_img"
android:src="@drawable/detailed_daily_sum"
android:layout_centerVertical="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/neura_bar_img"
android:layout_alignBottom="@id/neura_bar_img"
android:layout_alignLeft="@id/neura_bar_img"
android:layout_alignRight="@id/neura_bar_img"
android:gravity="center"
android:id="@+id/detailed_goal_text"
android:textStyle="italic"
android:text="0"
android:textSize="30sp"
android:textColor="@color/graphicsBlue"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/detailed_bites_eaten_text"
android:layout_alignTop="@id/neura_bar_img"
android:layout_alignBottom="@id/neura_bar_img"
android:layout_alignLeft="@id/neura_bar_img"
android:layout_alignRight="@id/neura_bar_img"
android:gravity="center"
android:layout_marginRight="170dp"
android:layout_marginTop="10dp"
android:textStyle="bold|italic"
android:text="0"
android:textSize="45sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/sports_part_text"
android:layout_alignTop="@id/neura_bar_img"
android:layout_alignBottom="@id/neura_bar_img"
android:gravity="center"
android:layout_marginTop="58dp"
android:layout_marginLeft="0dp"
android:layout_toRightOf="@+id/neura_bar_img"
android:text="---"
android:textSize="30sp"
android:textColor="@color/graphicsOrange"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/bites_part_text"
android:layout_alignTop="@id/neura_bar_img"
android:layout_alignBottom="@id/neura_bar_img"
android:gravity="center"
android:layout_marginBottom="54dp"
android:layout_marginLeft="0dp"
android:layout_toRightOf="@+id/neura_bar_img"
android:text="0"
android:textSize="30sp"
android:textColor="@color/graphicsGrey"/>
</RelativeLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
- 这张照片是从LG G3拍摄的,但我在Moto G上看到了同样的问题
我不知道为什么会发生这种情况,也没有在网上找到任何类似的案例
提前谢谢 嗯,这可能是您正在使用的布局类型
屏幕密度不同,您使用的某些值(px、dp等)在不同的设备上看起来可能不一样
我几乎总是使用LinearLayout,因为我可以使用“weight”属性
我不知道这是否是您正在寻找的答案,但我尝试了:D您的imageView
缺少scaleType
属性,默认情况下该属性设置为fitcenter
,根据设备的不同进行设置,请尝试以下操作
<ImageView
android:id="@+id/ZKt_qF_kgP"
android:layout_width="270dp"
android:layout_height="113dp"
android:src="@drawable/neura_bar_img"
android:layout_centerVertical="true"
android:scaleType="fitXY"
/>
另外,不同的android通常有不同的屏幕指标:
LG 3:480dp x 835dp
马达G:360dp x 640dp
Nexus4(在我的例子中是默认的android studio预览版):384dp x 640dp
有关更多设备指标,请参见此部分。
如果要针对上述三个设备调整应用程序,则需要在相应的文件夹中为每个度量(此处为宽度)指定布局:
layout-sw360dp
layout-sw480dp
layout-sw384dp
很抱歉,我刚刚注意到XML代码丢失了。正如你现在看到的,还有0dp margin_,所以我不明白为什么它在任何手机中都会有所不同。你用什么样的布局来封装你的UI元素?例如,RelativeLayout
,LinearLayout
,…它们都被包装在一个RelativeLayout中。从技术上讲,我们看不到您的布局是如何构建的,我们需要查看完整的布局(例如您在imageView中使用了android:layout\u centerVertical=“true”
),我已经编辑了这个问题,并将整个cardView放在一起(整个布局真的很长。这只是有趣的部分)。我已经更新了我的答案。我希望能够支持所有设备,但我仍然不明白为什么这些视图之间的0dp间距会产生一个间隙。因为0dp=0px。所以我不在乎手机的密度。谢谢!我没有想过这一点。