【发布时间】:2015-10-29 02:39:02
【问题描述】:
所以我正在为我的第一个应用程序设计我的主页,当我模拟它时,我注意到我的秒表的尺寸由于某种原因变得更大了。所以我拿起我的手机在那里测试了它,结果并不漂亮。我使用了 dp,我几乎可以肯定它是 % 而不是设置值,所以我不知道它为什么会这样变化。
这是图片,所以它不会弄乱我的问题http://imgur.com/a/IKvdI
menu1_layout.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:gravity="center_horizontal">
<ImageView
android:layout_width="500dp"
android:layout_height="800dp"
android:id="@+id/imageView"
android:background="@drawable/background3" />
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:gravity="center_horizontal">
<Button
android:id="@+id/stopWatch"
android:layout_width="225dp"
android:layout_height="200dp"
android:background="@drawable/stopwatch2"
android:layout_marginTop="83dp"
android:layout_marginRight="3dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:gravity="center_horizontal"
android:layout_gravity="center_horizontal|bottom">
<Chronometer
android:id="@+id/aChronometer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="40sp"
android:textColor="#ffffff"
android:layout_marginBottom="144dp"
android:layout_above="@+id/editText"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:text="@string/Explanation"
style="@style/Base.TextAppearance.AppCompat.Medium"
android:layout_above="@+id/button"
android:layout_centerHorizontal="true"
android:layout_marginBottom="26dp"
android:textColor="#ffffff" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText2"
android:text="= 0"
android:layout_marginTop="8dp"
style="@style/Base.TextAppearance.AppCompat.Medium"
android:layout_alignTop="@+id/button"
android:layout_centerHorizontal="true"
android:layout_marginRight="-10dp"
android:textColor="#ffffff" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="50dp"
android:layout_height="40dp"
android:background="@drawable/cookie"
android:id="@+id/button"
android:layout_marginRight="-10dp"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="@+id/editText2"
android:layout_toStartOf="@+id/editText2"
android:layout_marginBottom="84dp" />
</RelativeLayout>
</FrameLayout>
【问题讨论】:
-
额外评论我最终将所有不必要的按钮更改为 imageview,但秒表必须是一个按钮,这就是我如何修复它的地方。 edit 我看到了权重和其他方法,但我不知道如何实现。有没有办法为某些对象创建设置大小,所以当背景变宽时,我的图像也会变宽。