gpt4 book ai didi

java - ScrollView 中的权重

转载 作者:行者123 更新时间:2023-11-30 01:24:41 25 4
gpt4 key购买 nike

我有一个任务 - 做一个这样的 Activity task这里照片占据了屏幕的一半,文字占据了另一半。一切都适用于权重,但有时文本会占用大量空间并且不适合屏幕,所以我用 ScrollView 覆盖了我的所有布局,但问题来了。如果所有内容都不适合一个屏幕,那么所有内容都应该看起来像那样 - 照片将占据可见屏幕的一半,而后半部分将包含可以适合那里的部分文本,当我滚动时,所有内容都应该滚动并且新文本将出现在底部。但我不明白如何意识到这一点,这里的权重以某种奇怪的方式工作,据我所知,标签 fillViewPort="true" 仅在没有任何内容可滚动且有内容时才会产生内容这个标签什么都不做。那么我怎样才能使我的 View 以正确的方式显示呢?

这是我的 XML

<?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"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="leopikinc.musiciansyandex.MusicianInfo"
android:orientation="vertical">

<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/big_photo"
android:src="@drawable/test"
android:layout_gravity="center" />
</LinearLayout>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Genres"
android:id="@+id/genres"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Album count"
android:id="@+id/album_count"
android:layout_below="@+id/genres"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Track count"
android:id="@+id/track_count"
android:layout_above="@+id/biography_string"
android:layout_toRightOf="@+id/album_count"
android:layout_toEndOf="@+id/album_count" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/biography_string_text"
android:id="@+id/biography_string"
android:layout_below="@+id/album_count"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Biography Text"
android:id="@+id/biography_text"
android:layout_below="@+id/biography_string"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
</LinearLayout>
</ScrollView>

最佳答案

我以编程方式实现了我的目标。在 Activity 中,我可以访问 ImageView 并设置它的高度 = 可见屏幕的一半。

ViewGroup.LayoutParams lp = bigphoto.getLayoutParams(); 
lp.height = getResources().getDisplayMetrics().heightPixels/2;
bigphoto.setLayoutParams(lp);

但我仍然不知道如何使用 XML 来实现这一点

关于java - ScrollView 中的权重,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36550193/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com