2015-05-11 35 views
0

所以我有一个relativelayout有一个按钮(其中8个坐落在线性布局)的xml布局文件。锚定在此布局的顶部是textview。当你点击按钮时,这个textview中的文本被改变,这是我以编程方式设置的,但是当文本改变时,它会重新排列整个布局,这对用户来说太重要了。我知道这是因为我的textview设置为wrap_content,但这是我可以解释多个屏幕的最佳方式。以编程方式动态文本视图的文本更改布局中的其他视图,我不想它

是否有任何方式可以设置布局,以便当textview更改文本的数量时,它不会更改布局的其余部分,并且仍然足够动态以适合Android用户的所有屏幕尺寸?

这是我的布局,非常感谢您的帮助!

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/RelativeLayout1" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
tools:context="${relativePackage}.${activityClass}" > 

<TextView 
    android:id="@+id/titleText" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_marginTop="15dp" 
    android:layout_marginBottom="15dp" 
    android:gravity="center" 
    android:paddingLeft="5dp" 
    android:paddingRight="5dp" 
    android:text="Here is a really long sentance about some ish so that i can see exactly How Much till it g" 
    android:textAllCaps="true" /> 

<LinearLayout 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" 
    android:layout_centerVertical="true"> 

    <TableRow 
     android:id="@+id/tableRow1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:weightSum="2" 
     android:layout_centerInParent="true" 
     android:layout_below="@+id/titleText"> 

     <Button 
      android:id="@+id/IdentityButton" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="wrap_content" 
      android:text="@string/List_Identity" /> 

     <Button 
      android:id="@+id/ConnectionsButton" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="wrap_content" 
      android:text="@string/List_Connections" /> 
    </TableRow> 

    <TableRow 
     android:id="@+id/tableRow2" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:layout_marginTop="5dp" 
     android:weightSum="2" 
     android:layout_below="@+id/tableRow1" > 

     <Button 
      android:id="@+id/ResourcesButton" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="@string/List_Resources" /> 

     <Button 
      android:id="@+id/SkillsButton" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="wrap_content" 
      android:text="@string/List_Skills" /> 
    </TableRow> 

    <TableRow 
     android:id="@+id/tableRow3" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:layout_marginTop="5dp" 
     android:weightSum="2" 
     android:layout_below="@+id/tableRow2" > 

     <Button 
      android:id="@+id/InterestsButton" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="wrap_content" 
      android:text="@string/List_Interests" /> 

     <Button 
      android:id="@+id/ResponsibilitiesButton" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="wrap_content" 
      android:text="@string/List_Responsibilities" /> 
    </TableRow> 

    <TableRow 
     android:id="@+id/tableRow4" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:layout_marginTop="5dp" 
     android:weightSum="2" 
     android:layout_below="@+id/tableRow3" > 

     <Button 
      android:id="@+id/BeliefsButton" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="wrap_content" 
      android:text="@string/List_Beliefs" /> 

     <Button 
      android:id="@+id/DirectionButton" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="wrap_content" 
      android:text="@string/List_Direction" /> 
    </TableRow> 
</LinearLayout> 

<Button 
    android:id="@+id/ListNext" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentEnd="true" 
    android:text="Next" /> 

<ImageButton 
    android:contentDescription="@string/WhereHelpContentDesc" 
    android:id="@+id/ListHelpButton" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_alignParentBottom="true" 
    android:src="@android:drawable/btn_star" /> 

回答

1

因此,在这种情况下,从UX的角度来看,我甚至无法想象如何做到这一点视觉上的工作。

你可以在这里做的最好的事情我认为会使textview在到达边界(只是文本,而不是整个视图)时收缩。

尝试使用这个TextView的实现这一点,让我知道:

https://stackoverflow.com/a/5535672/1154026

+0

我想这是一个长镜头,感谢您的帮助反正!我最终解决了这个问题,只是将所有可以改变textview的字符串变成大约相同的字数。它的贫民窟,但嘿,它得到了工作完成....我希望 – KellysOnTop23

+0

尝试我张贴的一个!它很容易实现,并且看起来更好。相信我 :) – VicVu

相关问题