2017-08-30 112 views
0

我是一个新的程序员。我遇到了一些屏幕问题,我的网格new screen shot显示为有线行(可能是因为屏幕宽度很窄)。我已经上传了我的问题和我的代码的照片。 我哪里错了?我可以修复吗?宽度变化与窄屏幕尺寸

my problem

<GridLayout 
    android:id="@+id/gameTableLayout" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="80dp" 
    android:layout_marginRight="80dp" 
    android:layout_marginTop="10dp" 
    android:gravity="center" 

    android:orientation="horizontal" 
    android:visibility="invisible"> 

    <!-- the 16 buttons --> 
    <!-- 1:  (0,0) --> 
    <Button 
     android:id="@+id/button1" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_alignLeft="@+id/gridLayout" 
     android:layout_alignStart="@+id/gridLayout" 
     android:layout_column="0" 
     android:layout_columnWeight="1" 
     android:layout_gravity="fill" 
     android:layout_row="0" 
     android:layout_rowWeight="1" 
     android:background="@drawable/border" 
     android:onClick="choosePlace" 
     android:tag="1" 
     android:text="1" 
     android:textSize="20sp" /> 

回答

0

创建不同屏幕的不同值的文件夹在以下答案: How to define dimens.xml for every different screen size in android?

然后写按钮大小不同在每个dimen.xml

<dimen name="btn_width">50dp</dimen> 

<dimen name="btn_width">30dp</dimen> 

<dimen name="btn_width">20dp</dimen> 

然后在你的xml中使用

android:layout_width="@dimen/btn_width" 
    android:layout_height="@dimen/btn_width" 
+0

谢谢!我在哪里声明btn_width? – michal

+0

:/res/values-sw320dp/dimens.xml /res/values-sw480dp/dimens.xml /res/values-sw700dp/dimens.xml /res/values-sw800dp/dimens.xml。例如。 “sw480dp”表示该文件夹将用于具有480dp +屏幕宽度的屏幕 –

+0

我打开了新的价值资源文件名值-sw480dp,如何在里面打开dimen文件夹?我试图站在价值sw480dp文件,并添加维度我试着所有3个选项(资源文件/文件/目录),但我看不到它。我不明白链接如何定义你输入的维度,并尝试自己搜索,我仍然混淆 – michal