1

enter image description hereAndroid以編程方式設計佈局

如何以編程方式在android中進行此佈局。

我只想一個想法不是整個編碼的東西。

+0

爲什麼圖像沒有顯示?你有沒有人看到這個圖像,這個問題與我一起? – Yawar

+0

我可以看到圖像。但你應該多解釋一下。哪些部分是佈局元素,什麼是靜態圖片?幾乎所有事情都可以用'RelativeLayout' –

+0

實際上我不知道如何添加這些類型的參數,android:layout_alignBottom,android:layout_alignLeft等 – Yawar

回答

2

這是答案,但不是直接的答案。這是我親自做的以編程方式創建複雜的佈局。

在XML中創建相同的佈局。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:src="@drawable/some_big_image" /> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="100dp" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:background="#DD000000" > 

    <ImageView 
     android:id="@+id/imageView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_centerVertical="true" 
     android:src="@drawable/ic_launcher" /> 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignTop="@+id/imageView2" 
     android:layout_toRightOf="@+id/imageView2" 
     android:text="TextView" 
     android:textColor="@android:color/white" /> 

    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBottom="@+id/imageView2" 
     android:layout_toRightOf="@+id/imageView2" 
     android:text="TextView" 
     android:textColor="@android:color/white" /> 
</RelativeLayout> 

現在從頂級父孩子

RelativeLayout mParent = new RelativeLayout(this); 
    RelativeLayout.LayoutParams mParentParams = new RelativeLayout.LayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT)); 
    mParent.setLayoutParams(mParentParams); 

    ImageView mBigImageView = new ImageView(this); 
    mBigImageView.setLayoutParams(mParentParams); 
    mParent.addView(mBigImageView); 

正如你實踐您可以直接代碼,而無需創建XML一樣。

0

基本思想:

  1. 創建RelativeLayout一種新的含有被對準底部

  2. 一個ImageView和兩個TextView設置RelativeLayout的α來調整透明度

+0

其實我不知道如何添加這些類型的參數,android:layout_alignBottom,android:layout_alignLeft等 – Yawar

+1

@Yawar請看看這個鏈接:http://developer.android.com/guide/topics/ui/layout/relative.html 這將給你一些基本想法 – hungr

0

你可以有一個相對佈局,其中包含一個大圖像的圖像視圖在它的下面,一個更多的線性佈局包含圖像和文字作爲「珍珠大陸...」和班輪佈局的背景應該是50-60%透明。 使用形狀爲LL創建背景。並將其設置爲對齊父級(相對)佈局的底部。 希望這可以幫到你

+0

其實我不知道如何添加這些類型的參數,android:layout_alignBottom,android:layout_alignLeft等 – Yawar

+0

它更好地在xml中創建佈局,然後在需要的地方膨脹。充氣後設置各項所需的值 –

+0

另外還有一個樣本提供了上面的 –