我正在尝试自己构建一个简单的Contacs卡。我只想在左上角看一张个人资料图片,大约是宽度的四分之一到三分之一,右边是姓名+描述。
无论我尝试什么,它总是看起来非常类似于下面的截图。
这是我的布局:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/activity_standard_padding"
android:clipToPadding="false"
android:scrollbarStyle="outsideOverlay"
style="@style/AppBaseThemeCardBG">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/nowCardStyle">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="top"
android:paddingRight="@dimen/activity_horizontal_margin">
<ImageView
android:id="@+id/schuckCard"
android:scaleType="fitCenter"
android:layout_gravity="top"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:orientation="vertical">
<com.mikebdev.douala.widget.RobotoTextView
android:id="@+id/schuckHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:typeface="roboto_condensed_light"
android:text="JESCO SCHUCK"
android:textSize="@dimen/textSizeVeryLarge" />
<com.mikebdev.douala.widget.RobotoTextView
android:id="@+id/body1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:typeface="roboto_condensed_light"
android:text="Description" />
</LinearLayout>
</LinearLayout>
</ScrollView>
这就是它的样子:
我希望图像大致与操作栏中的描述一样宽。显然我在这里残忍地失败了
答案 0 :(得分:1)
为布局权重使用不同的值。像4为图像和6为内容给它40‰的卡宽度
答案 1 :(得分:1)
考虑使用cardslib(https://github.com/gabrielemariotti/cardslib)进行卡片布局。它很好地组合在一起。
答案 2 :(得分:0)
修复了我的愚蠢问题:
在ImageView
我已声明android:scaleType="fitCenter"
,其中ImageView
显然也在我的布局中。
将scaleType更改为fitStart
时,我得到了我想要的结果。