【发布时间】:2014-01-21 23:18:08
【问题描述】:
经过长时间的搜索,只找到了缩放 ImageView 宽度的结果,我希望有人可以帮助我解决我的问题。
我有两个 LinearLayout 在彼此下方,并在运行时用 24 个 ImageView 填充它们(每个 LinearLayout 12 个)。两种布局都占用相同的高度空间,现在我想缩放 ImageView,使它们与包含它们的 LinearLayout 具有相同的高度,同时保持 ImageView 内图像的纵横比。
我尝试知道许多不同的东西,例如 setScaleType、setAdjustViewBounds 或编写我自己的 ImageView 类并覆盖 onMeasure,但到目前为止,ImageView 无法从其父布局中获取整个可用高度。
也许我没有将正确的想法结合在一起,所以我希望有人可以帮助我解决这个问题。
编辑:
源图像的大小始终为 92 x 128。
布局:
firstCardHolder 和 secondCardHolder 是保存 ImageViews 的布局。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:p1="http://schemas.android.com/apk/res/android"
p1:orientation="vertical"
p1:minWidth="25px"
p1:minHeight="25px"
p1:layout_width="match_parent"
p1:layout_height="match_parent"
p1:id="@+id/contentHolder">
<LinearLayout
p1:orientation="horizontal"
p1:minWidth="25px"
p1:minHeight="25px"
p1:id="@+id/timerLayout"
p1:gravity="center"
p1:layout_width="match_parent"
p1:layout_height="wrap_content"
p1:layout_alignParentTop="true"
p1:layout_marginTop="10dp"
p1:layout_marginLeft="5dp"
p1:layout_marginRight="5dp"
p1:layout_marginBottom="5dp">
<TextView
p1:text="03:00"
p1:layout_width="wrap_content"
p1:layout_height="match_parent"
p1:id="@+id/timerTextView"
p1:textSize="26dp" />
</LinearLayout>
<HorizontalScrollView
p1:minWidth="25px"
p1:minHeight="25px"
p1:id="@+id/wordListScroll"
p1:layout_width="match_parent"
p1:layout_height="wrap_content"
p1:layout_below="@+id/timerLayout"
p1:layout_marginLeft="5dp"
p1:layout_marginTop="5dp"
p1:layout_marginRight="5dp"
p1:layout_marginBottom="5dp">
<LinearLayout
p1:orientation="horizontal"
p1:minWidth="25px"
p1:minHeight="25px"
p1:layout_width="match_parent"
p1:layout_height="match_parent"
p1:id="@+id/wordScrollLayout"
p1:gravity="center_vertical" />
</HorizontalScrollView>
<LinearLayout
p1:orientation="horizontal"
p1:minWidth="25px"
p1:minHeight="25px"
p1:layout_width="match_parent"
p1:layout_height="wrap_content"
p1:id="@+id/footerLayout"
p1:layout_marginLeft="5dp"
p1:layout_marginRight="5dp"
p1:layout_marginTop="5dp"
p1:layout_marginBottom="15dp"
p1:layout_alignParentBottom="true"
p1:clipChildren="false"
p1:clipToPadding="false">
<TextView
p1:layout_width="match_parent"
p1:layout_height="match_parent"
p1:id="@+id/hiraganaCombo"
p1:gravity="center"
p1:textSize="32dp" />
</LinearLayout>
<HorizontalScrollView
p1:minWidth="25px"
p1:minHeight="25px"
p1:id="@+id/scrollLayout"
p1:layout_width="wrap_content"
p1:layout_height="match_parent"
p1:layout_below="@+id/wordListScroll"
p1:layout_marginTop="5dp"
p1:layout_marginBottom="5dp"
p1:layout_marginLeft="5dp"
p1:layout_marginRight="5dp"
p1:layout_above="@+id/footerLayout">
<LinearLayout
p1:orientation="vertical"
p1:minWidth="25px"
p1:minHeight="25px"
p1:layout_width="match_parent"
p1:layout_height="match_parent"
p1:id="@+id/scrollContentLayout">
<LinearLayout
p1:orientation="horizontal"
p1:layout_width="match_parent"
p1:layout_height="match_parent"
p1:layout_weight="0.5"
p1:id="@+id/firstCardHolder"
p1:background="#ff009411"
p1:minWidth="25px"
p1:minHeight="25px" />
<LinearLayout
p1:orientation="horizontal"
p1:layout_width="match_parent"
p1:layout_height="match_parent"
p1:layout_weight="0.5"
p1:id="@+id/secondCardHolder"
p1:background="#ffd20000" />
</LinearLayout>
</HorizontalScrollView>
</RelativeLayout>
【问题讨论】:
标签: android android-layout xamarin.android xamarin