【问题标题】:How can I design a layout bigger than phone's screen?如何设计比手机屏幕更大的布局?
【发布时间】:2013-06-07 21:54:46
【问题描述】:

我正在开发一个 Android 应用程序,我想在 Eclipse 中设计一个大于屏幕高度的布局。

我有一个片段的布局,这个片段将在FragmentActivity 上的ScrollView 内。

这是我的片段布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/user_pro_main_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/text_state"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/layout_state"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout>

我是否必须更改 android:layout_height="match_parent" 以使其在 eclipse 的设计器中更大?

如果我想在 Eclipse Designer 上看到更大的布局,我该怎么做?

【问题讨论】:

  • 使用 android:layout_height="wrap_content" 你的布局高度将匹配你的内容高度而不是屏幕,当然它应该是顶级布局

标签: android eclipse layout


【解决方案1】:

答案很简单:你无法在 Eclipse 编辑器上查看比屏幕更大的布局。

可能的解决方法:
1. 评论部分顶视图(可见)以查看底部(不可见),然后在准备启动时取消注释。
2. 将设备预览更改为更大的分辨率(Nexus 10),这将为您提供一些额外的空间。

【讨论】:

    【解决方案2】:

    您始终可以在 layout_height 中明确设置确切的 dp 值,但当然大多数时候我认为您不需要固定值,因此以编程方式进行。

    LinearLayout yourLayout; // Get it by findViewById()
    yourLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, your_calculated_height));
    

    【讨论】:

    • 感谢您的回答,但我需要在设计 Eclipse 视图时这样做。
    【解决方案3】:

    您将设置android:layout_height="wrap_content",当您在物理屏幕之外添加子元素时,它将继续拉伸布局。

    至于在 Eclipse 上查看这个,我不确定。我个人只会在设备上运行它来查看它。

    【讨论】:

      【解决方案4】:

      只需计算设备高度和宽度,然后在运行时在布局高度和宽度处将 int 值添加到计算的高度和宽度。

      public void deviceDisplay(){
      
        Display display = getWindowManager().getDefaultDisplay();
        int width = display.getWidth();
        int height = display.getHeight();
      
      
       }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-05-20
        • 1970-01-01
        • 2015-02-14
        • 2021-06-03
        • 1970-01-01
        • 2013-10-16
        • 1970-01-01
        相关资源
        最近更新 更多