android - 如何让我的设备上的布局像在 Eclipse 图形设计器中一样呈现?

标签 android eclipse layout rendering

我意识到 Eclipse 图形布局编辑器经常(通常?)不会以与物理设备或模拟器相同的方式呈现内容。我通常可以处理。但是,我有一种情况,我无法弄清楚为什么会有这么大的差异,更重要的是,我无法弄清楚如何在目标设备上获得我想要的布局。

我正在尝试使用一些带有自定义图形文件的自定义 ImageButton 小部件作为按钮。我只是想让按钮填充它们所在的父布局。在设计器中,它们看起来像我认为的那样。但是当我在设备上运行它时,按钮太小了。这是设计的样子,使用设置为模拟我正在测试的 Droid X 的设备。

http://pozzy.com/consulting/LayoutDesignInEclipse.PNG

这是在我的 Droid X 上运行时的屏幕截图:

http://pozzy.com/consulting/ScoreEntryDroidXScreenCapture.png

我试图精简代码,但它仍然依赖于一些按钮图像文件。这是布局 XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    Android:layout_height="fill_parent">

     <LinearLayout
         android:id="@+id/scoreEntryPlayersAndMainEntry"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:orientation="horizontal" >

         <LinearLayout
             android:id="@+id/scoreEntryPlayers"
             android:layout_width="0dp"
             android:layout_height="fill_parent"
             android:layout_weight=".5"
             android:orientation="vertical"
             android:paddingBottom="4dp"
             android:paddingTop="4dp"
             android:paddingLeft="4dp" >                                             
         </LinearLayout>

         <LinearLayout
             android:id="@+id/scoreEntryMainEntry"
             android:layout_width="0dp"
             android:layout_height="fill_parent"
             android:layout_weight=".5"
             android:maxWidth="100dp"
             android:orientation="vertical"
             android:paddingBottom="4dp"
             android:paddingLeft="4dp"
             android:paddingRight="4dp"
             android:paddingTop="4dp" >

             <LinearLayout android:id="@+id/scoreEntryPreviousHoleNumberNextRow"
                 android:orientation="horizontal"
                   android:background="@drawable/score_entry_background_top"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 android:layout_weight=".1"
                 android:gravity="center|top" >

                 <ImageButton
                     android:id="@+id/previousHoleButton"
                     android:layout_width="0dp"
                     android:layout_height="fill_parent"
                    android:layout_weight="2"
                     android:layout_margin="5dp"
                    android:scaleType="fitCenter"
                     android:background="@null"
                     android:contentDescription="Previous Hole"
                     android:src="@drawable/score_entry_prev" />

                 <TextView
                     android:id="@+id/holeNumber"
                     android:layout_width="0dp"
                     android:layout_height="match_parent"
                     android:layout_weight="1"
                     android:background="@null"
                     android:paddingTop="20dp"
                     android:text="##"
                     android:textColor="#FFFFFF"
                     android:textSize="24sp"
                     android:textStyle="bold" />

                    <ImageButton
                        android:id="@+id/nextHoleButton"
                        android:layout_width="0dp"
                        android:layout_height="fill_parent"
                    android:layout_weight="2"
                        android:layout_margin="5dp"
                        android:scaleType="fitCenter"
                        android:background="@null"
                        android:contentDescription="Next Hole"
                        android:src="@drawable/score_entry_next" />
             </LinearLayout>

             <LinearLayout
                 android:id="@+id/scoreEntryCurrentScore"
                   android:background="@drawable/score_entry_background_middle"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 android:layout_weight=".8" >

                 <FrameLayout
                     android:id="@+id/scoreEntryScoreOverlays"
                     android:layout_width="fill_parent"
                     android:layout_height="wrap_content" >
                     <LinearLayout
                         android:visibility="invisible"
                         android:id="@+id/scoreEntryPlayerScoreLayout"
                         android:layout_width="fill_parent"
                         android:layout_height="wrap_content"
                         android:orientation="vertical" >

                         <TextView
                             android:id="@+id/currentPlayer"
                             android:layout_width="fill_parent"
                             android:layout_height="wrap_content"
                             android:layout_margin="10dp"
                             android:gravity="center"
                             android:text="Player Name"
                             android:textColor="#aaaaaa"
                             android:textSize="16sp"
                             android:textStyle="italic" />

                         <TextView
                             android:id="@+id/currentScore"
                             android:layout_width="fill_parent"
                             android:layout_height="fill_parent"
                             android:text="99"
                             android:gravity="center"
                             android:layout_gravity="bottom"
                             android:textColor="#ff0000"
                             android:textSize="100sp"
                             android:textStyle="bold|italic" />
                     </LinearLayout>
                </FrameLayout>
             </LinearLayout>

             <LinearLayout
                 android:id="@+id/scoreEntryScoreDownUpRow"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 android:background="@drawable/score_entry_background_bottom"
                 android:gravity="bottom"
                 android:layout_weight=".1"
                 android:orientation="horizontal" >
                 <ImageButton
                     android:id="@+id/scoreDownButton"
                     android:layout_width="0dp"
                     android:layout_height="fill_parent"
                     android:layout_margin="5dp"
                     android:layout_weight="1"
                     android:background="@null"
                     android:scaleType="fitCenter"
                     android:src="@drawable/score_entry_minus" />


                 <ImageButton
                     android:id="@+id/scoreUpButton"
                     android:layout_width="0dp"
                     android:layout_height="fill_parent"
                     android:layout_margin="5dp"
                     android:layout_weight="1"
                     android:background="@null"
                     android:scaleType="fitCenter"
                     android:src="@drawable/score_entry_plus" />

             </LinearLayout>

         </LinearLayout>
     </LinearLayout>     
</RelativeLayout>

如果您能帮助弄清楚如何让按钮填充各自的区域,我们将不胜感激!

最佳答案

我遇到了完全相同的问题,我不得不通过每次操纵它来解决它以适应这两个令人难过的地方。 eclipse 图形可视化工具有时真的很糟糕。我已经
试过 http://www.droiddraw.org/因为许多人说这非常好 - 但不知何故,在可视化工具上看到的内容与实际设备上看到的内容之间似乎存在差距。我想经验法则是遵循这个 http://developer.android.com/training/multiscreen/screensizes.html不折不扣地继续努力。我认为 Droid Draw 比 eclipse 更适合我,我想按照上面的开发链接并使用 say Droid Draw 应该最适合你。

关于android - 如何让我的设备上的布局像在 Eclipse 图形设计器中一样呈现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11113807/

相关文章:

java - Android - 将 Assets 复制到内部存储

android - Calendar.getDisplayName 返回 null

java - 如何从 NetBeans 中解开 Java EE 教程示例并将其与 Eclipse 一起使用?

c# - 如何使 TextBlock 在 GridViewColumn 中居中? (包括示例 xaml)

css - GWT布局问题

Android Google Maps Api V2 PolyLine 解码索引越界异常

java - 如何修复 m2eclipse 插件?

eclipse - 通过项目在Eclipse中搜索

android - RelativeLayout中不能存在循环依赖项吗?

java - 内存不足错误 : Java heap memory (GC heap)