Android 根据安卓手机的屏幕分辨率,dip并没有正确伸展
我使用了dip(例如:宽度=30dip,滚动条一直到屏幕中间)作为参数,但在3.5英寸的手机中,它看起来很好,在5英寸的屏幕手机中,直到中间才开始,这里是中间下方。为什么?Android 根据安卓手机的屏幕分辨率,dip并没有正确伸展,android,android-emulator,screen,density-independent-pixel,Android,Android Emulator,Screen,Density Independent Pixel,我使用了dip(例如:宽度=30dip,滚动条一直到屏幕中间)作为参数,但在3.5英寸的手机中,它看起来很好,在5英寸的屏幕手机中,直到中间才开始,这里是中间下方。为什么? xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"> <RelativeLay
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="450dip"
android:paddingLeft="10dip">
<ImageView
android:id="@+id/gdi_arrow_up"
android:layout_width="27dip"
android:layout_height="27dip"
android:layout_marginLeft="10dip"
android:scaleType="fitCenter"
android:layout_marginBottom="-8dip"
android:src="?attr/asListArrowUp" />
<include layout="@layout/main_menu"/>
<ImageView
android:id="@+id/gdi_arrow_down"
android:layout_width="27dip"
android:layout_height="27dip"
android:scaleType="fitCenter"
android:layout_marginBottom="-8dip"
android:layout_below="@android:id/list"/>
</RelativeLayout>
xmlns:android=”http://schemas.android.com/apk/res/android"
android:layout\u width=“包装内容”
android:layout\u height=“wrap\u content”>
dip代表密度无关像素,这意味着两个大小相同但密度不同的屏幕将对该值进行相同的处理,但两个大小不同的屏幕(大屏幕与普通屏幕)将对该值进行不同的处理
您的5英寸手机可能被报告为与正常手机一样大,而您的3.5英寸手机可能是导致此问题的原因,但我不确定
此外,在您的实际布局中,我建议使用match_parent作为高度,您通常不会对视图组使用设置宽度。将RelativeLayout的布局参数动态设置为screenWidth/2。它将在所有设备上都起作用 在onCreate中,执行以下操作:-
RelativeLayout rel = (RelativeLayout) findViewById(R.id.rel1);
int screenHeight = getWindowManager()
.getDefaultDisplay().getHeight();
rel.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, screenHeight/2));
希望这有帮助。添加一些代码、屏幕截图或任何有助于其他答案的信息。请看,在我硬编码的450中,如何克服这一点?哦,我们需要从语法上理解这些东西,我明白了。但他们说使用dip技术对所有屏幕都有效,为什么?艾露华塔的回答解释了这一点。