2015-08-27 99 views
0

我有一个登录窗口中有一个注册按钮,但由于某种原因,在较小的显示器上,此按钮似乎自己做了。 Devices按钮在多个显示器上显示不正确

1)我不想让按钮拉伸,就像它旋转时一样,但另一方面,我不希望按钮有文本显示“Regi ...”,因为按钮太小而不适合文本?

我曾尝试添加填充,边距等。如果屏幕太小,不知道如何将其设置为“动态”大小。

请参见下面的XML代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:tools="http://schemas.android.com/tools" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:background="@drawable/bg" 
      android:orientation="vertical" 
      tools:context="com.myapp.app.ui.LoginActivity" 
> 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    >> 

    <include 
     layout="@layout/login_and_register_header" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     /> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/white" 
     android:orientation="vertical"> 


     <com.myapp.app.ui.CustomEditText 

      android:id="@+id/edit_text_username" 
      android:layout_width="fill_parent" 
      android:layout_height="72dip" 
      android:layout_marginLeft="16dip" 
      android:layout_marginRight="16dip" 
      android:ems="10" 
      android:hint="Username or email" 
      android:inputType="textEmailAddress" 
      android:singleLine="true" 
      android:textColorHint="@color/bob_light_text" 
      android:textCursorDrawable="@drawable/orange_cursor" 
      android:typeface="normal"/> 

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

      <com.myapp.app.ui.CustomEditText 
       android:id="@+id/edit_text_password" 
       android:layout_width="0dp" 
       android:layout_height="72dip" 
       android:layout_centerHorizontal="true" 
       android:layout_marginLeft="16dip" 
       android:layout_weight="80" 
       android:ems="10" 
       android:hint="Password" 
       android:inputType="textPassword" 
       android:singleLine="true" 
       android:textColorHint="@color/bob_light_text" 
       android:textCursorDrawable="@drawable/orange_cursor" 
       android:typeface="normal"/> 

      <TextView 
       android:id="@+id/textView_forgotPassword" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="20" 
       android:text="Forgot?" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:textColor="@color/bob_links" 
       android:clickable="true" 
       android:layout_marginRight="3dp"/> 

     </LinearLayout> 


    </LinearLayout> 

    <View 
     android:layout_width="fill_parent" 
     android:layout_height="2dip" 
     android:background="@drawable/gradient" 
     > 
    </View> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:padding="16dip"> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:background="@drawable/white_edit_text_background" 
      android:orientation="horizontal" 
      android:layout_marginLeft="16dp" 
      android:layout_marginTop="16dp" 
      android:paddingEnd="16dp" 
      android:paddingStart="16dp" 
      android:paddingTop="16dp" 
      android:paddingBottom="16dp" 
      android:layout_marginRight="16dp" 
      android:gravity="center" 
      android:baselineAligned="false" 
      > 

      <TextView 
       android:id="@+id/textView3" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Register to join, \nit&apos;s free and easy" 
       android:textAppearance="?android:attr/textAppearanceSmall" 
       android:textSize="16dip" 
       android:paddingBottom="8dip" 
       android:layout_gravity="center_vertical" 
       /> 

      <Button 
       android:id="@+id/imageButton" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:background="@drawable/blue_background_2dp_radius" 
       android:text="Register" 
       android:textColor="@color/white" 
       android:layout_gravity="center_vertical" 
       android:textSize="14dip" 
       android:lines="1" 
       android:singleLine="true" 
       /> 

     </LinearLayout> 

     <View 
      android:layout_width="fill_parent" 
      android:layout_height="2dip" 
      android:background="@drawable/gradient" 
      android:layout_marginRight="16dip" 
      android:layout_marginLeft="17dip"> 
     </View> 


    </LinearLayout> 

</LinearLayout> 


<ProgressBar 
    android:id="@+id/myProgressBar" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true" 
    android:indeterminate="false"/> 

这里是问题具体到按钮的代码:

   <Button 
       android:id="@+id/imageButton" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:background="@drawable/blue_background_2dp_radius" 
       android:text="Register" 
       android:textColor="@color/white" 
       android:layout_gravity="center_vertical" 
       android:textSize="14dip" 
       android:lines="1" 
       android:singleLine="true" 
       /> 

如果这里它需要的是背景的代码按钮:

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
<solid android:color="@color/bob_bright_blue"/> 

<corners 
    android:radius="2dp"/> 
</shape> 
+0

http://stackoverflow.com/questions/5761960/what-是差异之间的匹配父母和填写父母 – 2Dee

+0

谢谢你,这简单地解决了它在整个屏幕上延伸的事实。最大的问题是,在小屏幕上按钮变得太小了? – x10sion

回答

2

请勿在按钮的layout_width属性上使用fill_parent,而应使用wrap_content。

<Button 
    android:id="@+id/imageButton" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@drawable/blue_background_2dp_radius" 
    android:text="Register" 
    android:textColor="@color/white" 
    android:layout_gravity="center_vertical" 
    android:textSize="14dip" 
    android:lines="1" 
    android:singleLine="true" /> 

这将使你的按键仅生长,直到其内容完全显示

投票,如果我帮你:d

+0

谢谢你,这简单地解决了它横跨屏幕延伸的事实。最大的问题是,在小屏幕上按钮变得太小了? – x10sion

+1

您可以使用XML属性设置最小宽度,但这不是最好的主意。在较小的屏幕上,您必须减小字体大小以适应按钮的最大宽度。 – alcaamado

+0

好的,谢谢磨坊!这样做真的很高兴,但看起来像我将不得不 – x10sion