2016-02-26 69 views

回答

0

您可以在这里找到一个解决方案:

https://stackoverflow.com/a/25143739/5907003

如果你想calculate the height dynamically您可以使用下面的代码:

int finalHeight, finalWidth; 
final ImageView iv = (ImageView)findViewById(R.id.scaled_image); 
final TextView tv = (TextView)findViewById(R.id.size_label); 
ViewTreeObserver vto = iv.getViewTreeObserver(); 
vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { 
    public boolean onPreDraw() { 
     iv.getViewTreeObserver().removeOnPreDrawListener(this); 
     finalHeight = iv.getMeasuredHeight(); 
     finalWidth = iv.getMeasuredWidth(); 
     tv.setText("Height: " + finalHeight + " Width: " + finalWidth); 
     return true; 
    } 
}); 

还只是一个想法,如果可以帮助,你可以将图像分成两部分,并将它们与您的布局对齐,以对齐底部并将顶部对齐相应的布局

对于圆角背景,您可以在可绘制文件夹中创建一个bg.xml

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="#FFFFFF"/> 
    <stroke android:width="3dip" android:color="#B1BCBE" /> 
    <corners android:radius="10dip"/> 
    <padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" /> 
</shape> 

祝你好运!

1
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.example.testing.MainActivity" > 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:background="#0000ff" 
     android:orientation="vertical" 
     android:layout_weight="1" /> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:background="#00ffff" 
     android:orientation="vertical" 
     android:layout_weight="1" /> 

</LinearLayout> 

<LinearLayout 
    android:layout_width="100dp" 
    android:layout_height="100dp" 
    android:orientation="vertical" 
    android:background="#00ff00" 
    android:layout_gravity="center" /> 

</FrameLayout> 

它看起来像这样 enter image description here

+0

下部应根据版面内容 –

+0

可以使用在较低的线性布局 –

+0

但上半部分滚动型也应随之移动起来是高度伸展。 –