[英]Textviews at the end of screen in LinearLayout
它具有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>
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>
您的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"/>
嘗試這個!
在您的<ImageView>
scaleType為android:scaleType="fitStart"
更改為android:scaleType="fitXY"
不要將Scrollview用作父視圖,並在圖像視圖中添加android:adjustViewBounds =“ true”以使其適合。
<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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.