我正在尝试使用 Android Studio 和 Firebase 构建我的第一个 Android 应用。我已将其全部连接起来,它可以很好地显示数据库中的内容和 firebase 存储中的图像。问题是,出于某种原因,我添加到 xml 中的文本没有显示出来。帖子底部有 3 个按钮,“喜欢”、“评论”和“重新发布”,它们有一个图标,然后是旁边的文字。图标显示完美,但文本不会显示。 这是问题所在的“include_post_actions.xml”......
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_below="@+id/post_action_layout"
android:layout_above="@+id/include"
android:layout_width="match_parent"
android:layout_height="75dp"
android:layout_weight="1"
android:gravity="center_vertical">
<LinearLayout
android:id="@+id/post_action_buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<com.like.LikeButton
app:icon_type="heart"
app:icon_size="18dp"
android:id="@+id/star_button"
android:layout_width="18dp"
android:layout_height="18dp" />
<TextView
android:id="@+id/post_likes_count"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:textColor="@color/colorBlack"
android:maxLines="1"
tools:text="Like" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<ImageView
android:id="@+id/post_comment_icon"
android:layout_width="20dp"
android:layout_height="20dp"
android:src="@drawable/ic_question_answer_black_24dp" />
<TextView
android:id="@+id/post_comments_count"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:textColor="@color/colorBlack"
android:maxLines="1"
tools:text="Comment" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<ImageView
android:id="@+id/post_repost_icon"
android:layout_width="20dp"
android:layout_height="20dp"
android:src="@drawable/ic_autorenew_black_24dp" />
<TextView
android:id="@+id/post_repost_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:textColor="@color/colorBlack"
android:maxLines="1"
tools:text="Repost" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/post_action_buttons">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginStart="20dp"
android:gravity="center_vertical"
tools:text="Likes Count"
android:id="@+id/like_count_text"
android:maxLines="1" />
</LinearLayout>
</RelativeLayout>
在预览中,文本显示在图标旁边,但当我在模拟器上运行它时,只有图标在那里,我不明白为什么。请帮忙。谢谢你。 Android Studio 中的预览
最佳答案
问题是您正在使用 tools:text="Repost"
。那只显示在预览模式下,你需要使用 android:text="Repost"
才能真正显示它。
tools
命名空间仅供编辑器使用,是一种无需实际设置值即可对齐内容的好方法。但是,如果您想要实际显示文本,则需要使用 android
命名空间。
关于java - 文本未显示在 android 上,但在 android studio 中显示在预览中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46374064/