LinearLayout中屏幕末尾的Textviews

时间:2018-02-28 11:41:08

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

它是一个简单的线性布局,包含1个ImageView和6个TextView以及一个ScrollView,但TextViews出现在屏幕的末端而不是ImageView下方。我已尝试在styles.xml中编辑我的dp值,但仍然无法正常工作请看看!! 我也尝试过编辑我的ImageView标签,但仍然无法正常工作,也不知道为什么TextView会出现在屏幕的末尾,如果我删除了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>

Styles.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

3 个答案:

答案 0 :(得分:2)

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"/> 这就是你的temp=df[df.duplicated(subset=['Individual'],keep=False)] print temp.groupby(['Individual'])['Company'].unique() >>>1 [A, B] >>>3 [A, C] 位于屏幕底部的原因

尝试将此设置静态高度设为button{ height: 50px; } .container div{ display: inline-block; height: 70px; border: 2px solid black; padding: 10px; } h1{ display: inline-block; } .container { display:flex; align-items:center; }

<div class="container"><div></div>
<button>Button</button>
<span>Span</span>
<div>div</div>
</div>

答案 1 :(得分:1)

试试这个!

<ImageView> scaleType android:scaleType="fitStart"将其更改为android:scaleType="fitXY"

答案 2 :(得分:1)

不要将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>