2014-11-25 65 views
0

我有一個啓動屏幕,它在屏幕的中心顯示Imageview中的應用程序徽標。顯示距離屏幕頂端30%距離處的Imageview android

我需要從屏幕頂部顯示imageview在距離30%,因此,在屏幕下方的70%看上去是空的

我有襯墊的想法,但不知道如何與此條件

<ImageView 
     android:id="@+id/img_splashlogo" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:contentDescription="SplashImage" 
     android:layout_margin="20dip" 
     android:src="@drawable/app_logo_splash" /> 

回答

3

在這裏使用%(百分比),你可以用把圖像中的線性佈局,然後將代碼中使用此代碼

LinearLayout ll = new LinearLayout(this); 
ll.setOrientation(LinearLayout.VERTICAL); 
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
    LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); 
layoutParams.setMargins(30, 20, 30, 0); 
Button okButton=new Button(this); 
okButton.setText("some text"); 
ll.addView(okButton, layoutParams); 
+0

我已經有了線性佈局.in xml ..我可以使用它還是需要在java代碼中創建? – 2014-11-25 12:48:10

+0

你需要在想要的java文件中使用此代碼鏈接到Splash屏幕視圖 – 2014-11-25 12:52:54

+0

或者還有一件事情首先嚐試在圖像頂部添加和隱藏視圖,然後在可見圖像頂部添加0.3重量通過android:visibility =「invisible」和android:weight =「0.30」來查看你的飛濺圖像 – 2014-11-25 12:56:50

1

試試這個,

<?xml version="1.0" encoding="UTF-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:background="@drawable/app_splash" > 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="0.30" 
      android:gravity="center" 
      android:orientation="vertical"> 

     <ImageView 
      android:id="@+id/img_splashlogo" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:contentDescription="SplashImage" 
      android:layout_margin="20dip" 
      android:src="@drawable/app_logo_splash" /> 


     </LinearLayout> 

     <View 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_width="0.70" 
      android:background="@android:color/transparent"/> 

    </LinearLayout> 
+0

哇...它的工作...感謝的人.... – 2014-11-25 13:07:47

+0

你可以幫個忙嗎..我發佈了一個問題,但仍然沒有人回覆它...你可以幫助在這種情況下。 。 – 2014-11-25 13:09:30