【问题标题】:Textviews at the end of screen in LinearLayout线性布局中屏幕末尾的文本视图
【发布时间】:2018-02-28 11:41:08
【问题描述】:

它是一个简单的线性布局,有 1 个 ImageView 和 6 个 TextViews 以及一个 ScrollView,但 TextViews 出现在屏幕的末尾而不是 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>

【问题讨论】:

  • 降低图像高度或固定 ImageView 高度。
  • 尝试给图像固定高度。

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


【解决方案1】:

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"/>

【讨论】:

  • @SahilShokeen 很乐意帮助你,我的朋友
【解决方案2】:

试试这个!

在你的&lt;ImageView&gt; scaleTypeandroid:scaleType="fitStart" 将其更改为android:scaleType="fitXY"

【讨论】:

    【解决方案3】:

    不要使用 Scrollview 作为父视图,并将 android:adjustViewBounds="true" 添加到 Imageview 以适应。

    <LinearLayout 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">
    
    <ScrollView
        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"
       >
    
        <ImageView
            android:scaleType="fitStart"
            android:layout_width="match_parent"
            android:adjustViewBounds="true"
            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>
    </LinearLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-08
      • 1970-01-01
      • 2023-03-23
      • 1970-01-01
      相关资源
      最近更新 更多