我有两个类似的问题,双方围绕涉及的ImageView
推动TextView
(S)和我想不出为什么。对于卡片列表,我希望图像的高度与其父母相匹配,而宽度适当地缩放,并且文字左对齐图像的右侧。对于弹出窗口,请使用下面的文本将宽度缩放到父级和缩放高度。避免Android在布局中将项目推出屏幕?
当前card_layout.xml
:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="120dp" >
<android.support.v7.widget.CardView
android:id="@+id/card_view"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_margin="10dp"
android:layout_height="120dp"
card_view:cardCornerRadius="4dp"
card_view:elevation="14dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/image"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:scaleType="fitStart"
android:padding="4dp"
android:layout_gravity="left"
android:layout_weight="1">
</ImageView>
<TextView
android:id="@+id/location"
android:textSize="16dip"
android:layout_toRightOf ="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="top" >
</TextView>
<TextView
android:id="@+id/abbreviation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/location"
android:layout_toRightOf="@+id/image"
android:layout_toEndOf="@+id/image">
</TextView>
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
当前location_info_card.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/info_image"
android:layout_height="0dp"
android:layout_width="match_parent"
android:scaleType="fitStart"
android:padding="10dp"
android:layout_weight="1">
</ImageView>
<TextView
android:id="@+id/info_abbreviation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingBottom="4dp">
</TextView>
<TextView
android:id="@+id/info_location"
android:textSize="16sp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingBottom="4dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
</LinearLayout>
我从教程以及与单一和嵌套布局SO帖子尝试了几种解决方案,但似乎没有任何工作至今。这只是我目前所拥有的。
- 解决方案?
- 为什么文本被推到LinearLayout的底部而不是直接出现在底部?或者为什么它在和
layout_toRightOf
上TextView
上使用wrap_content
时在RelativeLayout
的屏幕上被推下?
关于#2,由于类似问题上的答案只针对特定的问题发布解决方案,没有任何解释,我似乎无法将其应用于我的情况。我正在寻找一种资源来理解布局和视图如何相互作用(单个和什么时候嵌套),如果解释太长的答案。
您应该使用嵌套的布局和使用权重属性:) – HelloSadness
对于弹出,请尝试在'ImageView'取出'layout_weight',其'layout_height'设置为'wrap_content'。 – clownba0t
关于该卡,我在本地尝试了您的布局,并为我工作。只是为了确认,文本视图是否可见,使用白色以外的字体颜色,并且它们应该以编程方式正确显示文本? – clownba0t