即時通訊開發一個應用程序之間,並有像這樣的情況: 保持固定的利潤率按鈕的Android
我從圖片2個按鈕,他們必須適應整個屏幕。 因此,我使用了線性佈局,並將layout_weight設置爲1。 但是,從我的素描中可以看出,它們不是直角的,所以右邊的那個必須有負的左邊距,以便看起來像素描。但圖像是動態縮放的,因此保證金數量取決於屏幕尺寸。我試圖爲ldpi,mdpi,hdpi等創建多個維度文件,但只能在預覽2個hdpi屏幕中查看它看起來不一樣。瞭解原始尺寸裕度是否有任何方法在所有屏幕上正確縮放它?
問候
編輯: OFC我使用dp單位。但就像我說過的,對於所有具有相同dpi的屏幕來說都不一樣。 例如:
值-xhdpi/dimens.xml:
<resources>
<dimen name="button_margin">-23dp</dimen>
</resources>
Nexus 10的2560x1600的xhdpi:
的Galaxy Nexus 720x1280 xhdpi:
我的佈局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/riderstabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal">
<ImageView
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:checked="true"
android:layout_weight="1"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:src="@drawable/btn1" />
<ImageView
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:layout_marginLeft="@dimen/button_margin"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:src="@drawable/btn2" />
</LinearLayout>
<android.support.v4.view.ViewPager
android:id="@+id/list"
android:background="@android:color/transparent"
android:layout_weight="7"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</android.support.v4.view.ViewPager>
</LinearLayout>
編輯:
我發現,還有屏幕尺寸的另一個類別。
由於documenatation說: 大小:小,中,大,XLARGE 密度:LDPI(低),於mdpi(中),華電國際(高),並且xhdpi(超高)我認爲有xxhdpi,xxxhdpi和tvhdpi太]。
所以我有2個按鈕:262x46第一和404x46秒。 -26像素是完美匹配的第二個按鈕的原始邊距。 (所以總數是404 + 262-26 = 640)。
我發現一些因素密度: LDPI - 0.75 MDPI - 1.0 華電國際 - 1.5 xhdpi - 2.0 xxhdpi - 3.0 xxxhdpi - 4.0
但是,當我如猜對了餘地mdpi並將其乘以1.5,對於hdpi它沒有正確縮放(就像在eclipse中查看預覽一樣)。而且還有屏幕尺寸,所以它更加複雜。
您的意思是保證金數量取決於屏幕密度?它看起來像我,如果你使用'dp'的餘量,你可以很容易地實現你正在描述的 – SDJMcHattie