【问题标题】:Placing A TextView in the centre of ImageView inside TableRow在 TableRow 内 ImageView 的中心放置一个 TextView
【发布时间】:2013-12-09 16:11:41
【问题描述】:

我是 Android 新手,我想在 TableRow 内的 ImageView 中心放置一个 TextView。 textView 与图像视图分开,我怎样才能将 textView 放在 imageView 的顶部?而且因为它在 tableRow 里面,所以我不能使用 layout_alignLeft 或 layout_alignRight 来居中。

非常感谢您帮助我。

类似:

<TableRow>
<ImageView
    android:id="@+id/durationView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:src="@drawable/blk_duration"
    android:contentDescription="@string/logo"
    android:layout_weight="1" />

    <TextView
        android:id="@+id/durationTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="@string/duration"
        android:textColor="@color/text_color"
        android:textSize="@dimen/font_size_duration" />

    <ImageView
    android:id="@+id/durationView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:src="@drawable/blk_duration"
    android:contentDescription="@string/logo"
    android:layout_weight="1" />

    <TextView
        android:id="@+id/durationTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="@string/duration"
        android:textColor="@color/text_color"
        android:textSize="@dimen/font_size_duration" />

</TableRow>

【问题讨论】:

    标签: android android-layout


    【解决方案1】:

    尝试以下布局:

    <TableRow>
        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1" >
    
            <ImageView
                android:id="@+id/durationView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:contentDescription="@string/logo"
                android:src="@drawable/blk_duration" />
    
            <TextView
                android:id="@+id/durationTextView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:gravity="center"
                android:text="@string/duration"
                android:textColor="@color/text_color"
                android:textSize="@dimen/font_size_duration" />
    
        </RelativeLayout>
        <RelativeLayout
            android:layout_width="odp"
            android:layout_height="wrap_content"
            android:layout_weight="1" >
    
            <ImageView
                android:id="@+id/durationView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:contentDescription="@string/logo"
                android:src="@drawable/blk_duration" />
    
            <TextView
                android:id="@+id/durationTextView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:gravity="center"
                android:text="@string/duration"
                android:textColor="@color/text_color"
                android:textSize="@dimen/font_size_duration" />
    
        </RelativeLayout>
    </TableRow>
    

    【讨论】:

      【解决方案2】:

      在 Tablerow 中使用相对布局。然后在 relativelayout 中放置 imageview 和 textview。通过将 ui 拖动到您需要放置的位置来相应地调整您的文本视图。希望我能回答你的问题。

      【讨论】:

      • 我曾尝试在TableRow内放置一个相对布局,但宽度比屏幕宽。
      • 使用相对布局matchparent的布局宽度
      猜你喜欢
      • 2015-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多