Android 将文本视图放置在TableRow内ImageView的中心
我是Android新手,我想在TableRow中的ImageView中间放置一个TextView。文本视图与图像视图分开,如何将文本视图放在图像视图的顶部?因为它在tableRow内,所以我不能使用layout_alignLeft或layout_alignRight来居中 非常感谢你帮助我 比如:Android 将文本视图放置在TableRow内ImageView的中心,android,android-layout,Android,Android Layout,我是Android新手,我想在TableRow中的ImageView中间放置一个TextView。文本视图与图像视图分开,如何将文本视图放在图像视图的顶部?因为它在tableRow内,所以我不能使用layout_alignLeft或layout_alignRight来居中 非常感谢你帮助我 比如: <TableRow> <ImageView android:id="@+id/durationView" android:layout_width="fill_par
<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>
在Tablerow中使用relativelayout。然后在relativelayout中放置imageview和textview。通过将ui拖动到需要放置的位置,相应地调整textview。希望我能回答您的问题。尝试以下布局:
<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>
我尝试在TableRow内放置相对布局,但宽度比屏幕宽。请使用相对布局的布局宽度