我需要一些Android布局帮助。 我想要的是一个布局,其中灰色视图周围的视图随着屏幕大小而增长,并且中间的视图始终居中。 如果屏幕会很小,触及左右灰色视图的宽度应为0 ... 我制作了Imageviewer,灰色区域是图像,外部区域都有黑色背景。如果屏幕很小,图像应与屏幕匹配。但是如果它长大了,图像不能缩放,但它周围的区域应该增长......我希望你明白我的意思。 也许一个水平布局的垂直线性布局?Android xml布局(附图片)
谢谢!
我需要一些Android布局帮助。 我想要的是一个布局,其中灰色视图周围的视图随着屏幕大小而增长,并且中间的视图始终居中。 如果屏幕会很小,触及左右灰色视图的宽度应为0 ... 我制作了Imageviewer,灰色区域是图像,外部区域都有黑色背景。如果屏幕很小,图像应与屏幕匹配。但是如果它长大了,图像不能缩放,但它周围的区域应该增长......我希望你明白我的意思。 也许一个水平布局的垂直线性布局?Android xml布局(附图片)
谢谢!
试试这个:
这里,我们去:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/center"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_centerInParent="true"
android:background="#343434" />
<LinearLayout
android:id="@+id/top"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/center"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#ababab" />
<LinearLayout
android:id="@+id/left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/center"
android:layout_alignParentLeft="true"
android:layout_alignTop="@+id/center"
android:layout_toLeftOf="@+id/center"
android:background="#cfcfcf" />
<LinearLayout
android:id="@+id/right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/left"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/left"
android:layout_toRightOf="@+id/center"
android:background="#cfcfcf" />
<LinearLayout
android:id="@+id/bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/center"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:background="#ababab" />
</RelativeLayout>
周围的黑色边框!非常感谢你:) – user1886411
如果你不想放置任何东西在顶部,左边,右边,底部,你可以实际上只留下你的中心部件(布局),并给出了在@leenephi回答中描述的父亲RelativeLayout的黑色背景。 – Bostone
您可以通过设置各种屏幕尺寸方面处理大大小小的屏幕,因此,例如:
值/ dimens.xml:
<resources>
<dimen name="margin"0dp</dimen>
</resources>
价值观w480dp/dimens.xml:
<resources>
<dimen name="margin"3dp</dimen>
</resources>
价值观w600dp/dimens.xml:
<resources>
<dimen name="margin"6dp</dimen>
</resources>
等
现在你可以设置你的利润率您ImageView像这样:
android:layout_marginRight/Left="@dimen/margin"
不要忘记你的ImageView设置为
android:gravity="center"
如果你的布局只是仅由这个ImageView的,那么你可以离开了保证金,只是设置重力中心。
如果所有的外部空间只是要像你说的,那么为什么不只是有一个RelativeLayout的与中心内配置有固定layout_width和layout_height将保持不变上的所有设备的ImageView的黑色背景。用黑色背景设置RelativeLayout。这种方式会表现得更好,而且,如果你想要的只是图像周围的黑色边框,那么你不必担心在其他地方有实际的布局。只要你设定一个固定的宽度和高度并居中,它就应该按照你的意愿行事。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_centerInParent="true"
android:src="@drawable/apache" />
</RelativeLayout>
就像那样。或者使用“100px”,如果你想真正具体我想..虽然这不被推荐。
外部视图是否会包含任何内容或只是图像周围的黑色边框? – leenephi
他们不会包含任何东西。只是我正在寻找的图像 – user1886411