2015-10-09 97 views
0

我在一個佈局中有一個自定義聊天氣泡,另一個佈局中有一個進度欄。我知道如何將整個佈局包含在另一個佈局中。但是我想在另一個佈局中包含一個視圖,即進度條。如何在另一個佈局中包含進度欄視圖

這是我的聊天氣泡佈局。

<RelativeLayout 
android:id="@+id/message_content_box" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:padding="0dp"> 

<com.chatbubble.BubbleFrameLayout 
android:id="@+id/message_content" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_marginBottom="10dp" 
android:layout_marginLeft="10dp" 
android:paddingBottom="10dp" 
android:paddingLeft="10dp" 
android:paddingRight="18dp" 
android:paddingTop="10dp" 
custom:bubbleColor="@color/theme_light" 
custom:bubbleCornerRadius="6dp" 
custom:bubbleArrowType="standard" 
custom:bubbleArrowPosition="right" 
custom:bubbleArrowAlign="end" 
custom:bubbleArrowWidth="8dp" 
custom:bubbleArrowHeight="16dp" 
custom:bubbleArrowOffset="-14dp"> 

<include layout="@layout/message_content"/> 

</com.chatbubble.BubbleFrameLayout> 

<ImageView 
android:id="@+id/message_status" 
android:layout_width="20dp" 
android:layout_height="20dp" 
android:layout_alignBottom="@+id/message_content" 
android:layout_alignLeft="@+id/message_content" 
android:layout_marginBottom="-10dp" 
android:layout_marginLeft="-10dp" 
        android:contentDescription="@string/message_status_content_description" 
android:src="@drawable/ic_message_success" /> 
</RelativeLayout> 

以下是我的佈局與進度。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/message_file_controls" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content"> 

<RelativeLayout 
android:id="@+id/message_file_controls1" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_gravity="center" > 

<TextView 
android:id="@+id/file_title" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_marginTop="7dp" 
android:ellipsize="end" 
android:singleLine="true" 
android:text="IMG-55122.jpg (1.5M)" 
android:textAppearance="?android:attr/textAppearanceSmall" 
android:textScaleX="0.5" /> 

<ProgressBar 
android:id="@+id/file_progress" 
style="@android:style/Widget.ProgressBar.Horizontal" 
android:layout_width="160dp" 
android:layout_height="3dip" 
android:layout_alignParentBottom="true" 
android:layout_alignTop="@+id/file_status" 
android:layout_centerInParent="true" 
android:layout_gravity="top" 
android:background="@drawable/ab_bottom_solid_example" 
android:max="100" 
android:maxWidth="220dp" 
android:progress="0" 
android:progressDrawable="@drawable/message_ft_progress_bar" /> 

<TextView 
android:id="@+id/file_status" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_below="@id/file_title" 
android:layout_marginTop="2dp" 
android:text="0%" 
android:textAppearance="?android:attr/textAppearanceSmall" /> 

請幫忙。

回答

0

使用此:

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

    <ProgressBar 
     android:id="@+id/progressbar" 
     style="?android:attr/progressBarStyleLarge" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:visibility="visible" /> 


</RelativeLayout> 
0

可以膨脹的佈局,並添加你想要的看法,這樣的事情。

View rootView = inflater.inflate(R.layout.YOURXMLLAYOUT, null, false); 
    ProgressBar pb = (ProgressBar)rootView.findViewById(R.id.file_progress); 
    YourLayout.addView(pb); 

但如果我是在你的皮膚,我將只是做:

ProgressBar pb = new ProgressBar(this); 
YourLayout.addView(pb); 

HPPE這會有所幫助。

相關問題