java - LinearLayout 中屏幕末尾的 TextView

标签 java android android-layout android-linearlayout android-scrollview

它是一个简单的线性布局,具有 1 个 ImageView 和 6 个 TextView 以及一个 ScrollView,但 TextView 出现在屏幕的末端而不是 ImageView 下方。我已经尝试在 styles.xml 中编辑我的 dp 值,但仍然无法正常工作,请看一下!! 我也尝试过编辑我的 ImageView 标签,但仍然无法正常工作,并且不知道为什么 TextViews 出现在屏幕的末尾,如果我删除 ScrollView,文本将不可见。

布局代码:

<?xml version="1.0" encoding="utf-8"?>

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"     
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#000000"
tools:context="com.example.stan.sportbusinesscard.MainActivity">

<ImageView
    android:scaleType="fitStart"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:contentDescription="@string/photo_description"

    android:src="@drawable/photo"
    android:id="@+id/image"/>

<TextView
    style="@style/TitleText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/title" />


<TextView
    style="@style/LightText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/text1"/>
<TextView
    style="@style/TitleText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/where" />
<TextView
    style="@style/LightText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/address"
    android:autoLink="map"/>
<TextView
    style="@style/TitleText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/when" />
<TextView
    style="@style/LightText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/dateOf" />


 </LinearLayout>
</ScrollView>

样式.xml:

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>
<style name="LightText" parent="AppTheme">
    <!-- Customize your theme here. -->
    <item name="android:paddingLeft">18dp</item>
    <item name="android:paddingRight">18dp</item>
    <item name="android:textColor">#aaaaaa</item>

</style>
<style name="TitleText" parent="AppTheme">
    <!-- Customize your theme here. -->
    <item name="android:paddingLeft">18dp</item>
    <item name="android:paddingRight">18dp</item>
    <item name="android:paddingTop">20dp</item>
    <item name="android:textSize">18sp</item>
    <item name="android:textColor">#FFD700</item>

</style>
</resources>

enter image description here

最佳答案

您的 ImageView 高度是 wrap_content 这就是为什么您的 textview 位于屏幕底部的原因

尝试将静态高度设置为您的 ImageView

<ImageView
    android:scaleType="fitStart"
    android:adjustViewBounds="true"
    android:layout_width="match_parent"
    android:layout_height="150dp"
    android:contentDescription="@string/photo_description"    
    android:src="@drawable/photo"
    android:id="@+id/image"/>

关于java - LinearLayout 中屏幕末尾的 TextView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49028733/

相关文章:

android - 我怎样才能在 NestedScrollView 中使用 RecyclerView 工作 ViewPager

android - 当上面的布局高度缩小时向上移动布局

java - 将 ElasticSearch 与 Dropwizard 结合使用

java - Linux 中文件的奇怪 getName() 结果

java - Android 的 HSTS 或 ATS 等效项?

java - 是否可以有多个android :id/list?

android - 展开 ScrollView 下方的按钮

java - 将参数传递给 Java 方法内定义的方法

javascript - 如何在 Nativescript 中实现 Java 方法?

java - Android截击奇怪的错误