这是我使用的main.xml,myImage_Main和myImage_Main2中的两个图像混乱了。
有没有办法将android:layout_width设置为位图的大小?或者我只是将它设置为500px,大约是屏幕的大小?
我想要的例子:
Scroll view ------------------------------- | | Image 1 Full Sized on Screen | | | Bottom of screen ___________________________________________ | Not yet on screen, but | Scroll down to see Image 2 | | | | |_____________________________________________|
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="top"
>
<Button android:id="@+id/myButton_Search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/btn_search"
android:layout_gravity="top"
/>
<Button android:id="@+id/myButton_Save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/btn_save"
android:layout_gravity="top"
/>
</LinearLayout>
<EditText
android:id="@+id/myEdittext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
/>
<ScrollView android:id="@+id/ScrollView01"
android:layout_width= **Right here I want to get the size of the image i use as the width**
android:layout_height=**Right here I want to get the size of the image i use as the height**
android:fillViewport="true"
android:scrollY="100px"
>
<LinearLayout android:id="@+id/LinearLayout02"
android:layout_width=**Right here I want to get the size of the image i use as the width**
android:layout_height=**Right here I want to get the size of the image i use as the height**
android:orientation="vertical">
<ImageView android:id="@+id/myImage_Main"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitCenter"
/>
<ImageView android:id="@+id/myImage_Main2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitCenter"
/>
</LinearLayout>
</ScrollView>
</LinearLayout>
答案 0 :(得分:1)
只需使用wrap_content
即可。当布局在setContentView(R.layout.your_layout)
中膨胀时,它将确定显示其所有子视图所需的确切宽度。但是,您需要设置scaleType="none"
。我不完全确定你想要完成什么,所以如果我误解了这个问题,请澄清。