2015-01-08 50 views
2

我正在尝试将spinner/progress bar添加到TextView左侧将微调器/进度条添加到文本视图中?

________________ 
| O MY TEXT | 
|________________| 

O = spinner/progress bar 

起初,我想到的是增加一个TextView,并在其顶部添加ProgressBar。是否有可能在TextView本身做到这一点?如果不是这样做的最好方法是什么?

<RelativeLayout android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 

     <TextView 
      android:id="@+id/latlongLocation" 
      android:layout_width="150dp" 
      android:layout_height="23dp" 
      android:layout_alignParentBottom="true" 
      android:layout_centerHorizontal="true" 
      android:layout_marginBottom="21dp" 
      android:background="@drawable/black" 
      android:gravity="center" 
      android:singleLine="true" 
      android:textColor="#202020" 
      android:textSize="11sp" /> 

     <RelativeLayout android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 

      <ProgressBar 
       android:id="@+id/progressBar1" 
       style="?android:attr/progressBarStyleLarge" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true" 
       android:layout_centerHorizontal="true" /> 

     </RelativeLayout> 

    </RelativeLayout> 
+0

有你为什么在你的布局硬编码保证金和部件尺寸特殊的原因?您可以使用样式/维度资源来保持应用程序的一致性。关于文本颜色或绘图也是如此。 – 2Dee

+0

@ 2Dee我是Android SDK的新手,谨慎帮助我纠正我的代码? –

回答

4

使用FrameLayout。有了它,你可以像卡片堆栈中放置视图。

小例子:

<!-- Example of parent --> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:padding="16dp" 
    android:orientation="vertical"> 

    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@android:color/black"> 

     <ProgressBar 
      style="@android:style/Widget.ProgressBar.Large" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"/> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="90dp" 
      android:layout_marginTop="20dp" 
      android:textSize="32dp" 
      android:textColor="@android:color/white" 
      android:text="Test text"/> 
    </FrameLayout> 
</LinearLayout> 

看起来像这样

enter image description here

+0

真棒,但现在'TextView'和'ProgressBar'已经走到了左上角。 –

+0

你必须设置正确的边距,等待,我会编辑答案 – vilpe89

+0

我看起来更像这样:http://i.imgur.com/I10p8GD.png –