这是我的线性布局,我已经实现了以下目标..我想要消耗整页高度。所以我正在考虑布局的重量。但是图像正在拉伸
但是图像越来越紧张..我想用原版 图像的宽度..我需要做些什么改变?
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/mdfooter"
android:layout_below="@+id/mdtlone"
android:background="@color/white"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/one"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<ImageView
android:id="@+id/breakfastview"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/mealbreakfast"
android:clickable="true"
android:onClick="onClick"
android:scaleType="center" />
<TextView
android:id="@+id/tvrequiredbreakfast"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="normal" />
<TextView
android:id="@+id/breakfastactual"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:background="@drawable/newbuttonshape"
android:clickable="true"
android:gravity="center"
android:onClick="gotoCalorieMealsDiaryActivity"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="normal" />
</LinearLayout>
<LinearLayout
android:id="@+id/two"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<ImageView
android:id="@+id/lunchview"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/meallunch"
android:clickable="true"
android:onClick="onClick"
android:scaleType="center" />
<TextView
android:id="@+id/tvrequiredlunch"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="normal" />
<TextView
android:id="@+id/lunchactual"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:background="@drawable/newbuttonshape"
android:clickable="true"
android:gravity="center"
android:onClick="gotoCalorieMealsDiaryActivity"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="normal" />
</LinearLayout>
<LinearLayout
android:id="@+id/three"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<ImageView
android:id="@+id/dinnerview"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/mealdinner"
android:clickable="true"
android:onClick="onClick"
android:scaleType="center" />
<TextView
android:id="@+id/tvrequireddinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="normal" />
<TextView
android:id="@+id/dinneractual"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:background="@drawable/newbuttonshape"
android:clickable="true"
android:gravity="center"
android:onClick="gotoCalorieMealsDiaryActivity"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="normal" />
</LinearLayout>
<LinearLayout
android:id="@+id/four"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<ImageView
android:id="@+id/snackview"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/mealsnacks"
android:clickable="true"
android:onClick="onClick"
android:scaleType="center" />
<TextView
android:id="@+id/tvrequiredsnacks"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="normal" />
<TextView
android:id="@+id/snacksactual"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:background="@drawable/newbuttonshape"
android:clickable="true"
android:gravity="center"
android:onClick="gotoCalorieMealsDiaryActivity"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="normal" />
</LinearLayout>
<LinearLayout
android:id="@+id/five"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#E8E8E8" >
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="Total"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#4CC1D2"
android:textStyle="bold" />
<TextView
android:id="@+id/calorieoutput"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge"
android:textStyle="bold" />
<TextView
android:id="@+id/totalout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/newbuttonshape"
android:gravity="center"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
请提出建议
答案 0 :(得分:2)
src的背景背景&#34; android:src =&#34; @ drawable / mealbreakfast&#34;&#34;
<ImageView
android:id="@+id/breakfastview"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/mealbreakfast"
android:clickable="true"
android:onClick="onClick"
android:scaleType="center" />
答案 1 :(得分:0)
按照以下设计,您将能够解决您的问题。
我在这里仅针对一个ImageView进行了更改,您将在其他ImageView中执行相同操作。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/mdfooter"
android:layout_below="@+id/mdtlone"
android:background="@color/white"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/one"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" >
<ImageView
android:id="@+id/breakfastview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/mealbreakfast"
android:clickable="true"
android:onClick="onClick"
android:scaleType="center" />
</LinearLayout>
<TextView
android:id="@+id/tvrequiredbreakfast"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="normal" />
<TextView
android:id="@+id/breakfastactual"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:background="@drawable/newbuttonshape"
android:clickable="true"
android:gravity="center"
android:onClick="gotoCalorieMealsDiaryActivity"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="normal" />
</LinearLayout>
<LinearLayout
android:id="@+id/two"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<ImageView
android:id="@+id/lunchview"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/meallunch"
android:clickable="true"
android:onClick="onClick"
android:scaleType="center" />
<TextView
android:id="@+id/tvrequiredlunch"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="normal" />
<TextView
android:id="@+id/lunchactual"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:background="@drawable/newbuttonshape"
android:clickable="true"
android:gravity="center"
android:onClick="gotoCalorieMealsDiaryActivity"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="normal" />
</LinearLayout>
<LinearLayout
android:id="@+id/three"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<ImageView
android:id="@+id/dinnerview"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/mealdinner"
android:clickable="true"
android:onClick="onClick"
android:scaleType="center" />
<TextView
android:id="@+id/tvrequireddinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="normal" />
<TextView
android:id="@+id/dinneractual"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:background="@drawable/newbuttonshape"
android:clickable="true"
android:gravity="center"
android:onClick="gotoCalorieMealsDiaryActivity"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="normal" />
</LinearLayout>
<LinearLayout
android:id="@+id/four"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<ImageView
android:id="@+id/snackview"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/mealsnacks"
android:clickable="true"
android:onClick="onClick"
android:scaleType="center" />
<TextView
android:id="@+id/tvrequiredsnacks"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="normal" />
<TextView
android:id="@+id/snacksactual"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:background="@drawable/newbuttonshape"
android:clickable="true"
android:gravity="center"
android:onClick="gotoCalorieMealsDiaryActivity"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="normal" />
</LinearLayout>
<LinearLayout
android:id="@+id/five"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#E8E8E8" >
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="Total"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#4CC1D2"
android:textStyle="bold" />
<TextView
android:id="@+id/calorieoutput"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge"
android:textStyle="bold" />
<TextView
android:id="@+id/totalout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/newbuttonshape"
android:gravity="center"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge"
android:textStyle="bold" />
</LinearLayout>
这里你的ImageView被拉伸了所以我替换了
<ImageView
android:id="@+id/breakfastview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/mealbreakfast"
android:clickable="true"
android:onClick="onClick"
android:scaleType="center" />
使用我的代码
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" >
<ImageView
android:id="@+id/breakfastview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/mealbreakfast"
android:clickable="true"
android:onClick="onClick"
android:scaleType="center" />
</LinearLayout>
这不会拉伸你的ImageView,它看起来就像它一样。
希望这会有所帮助......谢谢