2016-03-21 69 views
0

好吧,有很多问题,但其中大多数都是旧的或每种情况都是独一无二的。如何定位动态添加的子文本视图和图像视图?

我有这个布局文件:

<?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="wrap_content" 
android:orientation="vertical" 
    android:gravity="center" 
    android:layout_marginLeft="20dp" 
    android:layout_marginRight="20dp" 
    android:id="@+id/phaseParent"> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="01" 
    android:textSize="16sp" 
    android:layout_marginLeft="-20dp" 
    android:id="@+id/phaseNumbers"/> 

    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 

     <ImageView 
      android:layout_width="30dp" 
      android:layout_height="30dp" 
      android:src="@drawable/state_bubble" 
      android:id="@+id/phaseBubbles"/> 
     <View 
      android:background="@color/verticalLine" 
      android:layout_width="70dp" 
      android:layout_height="2dp" 
      android:layout_marginTop="15dp" 
      android:id="@+id/break1"/> 
    </RelativeLayout> 

</LinearLayout> 

它是动态添加到基于列表中的项目总金额此父:

    <LinearLayout 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:orientation="horizontal" 
         android:id="@+id/phaseListItems" 
         android:gravity="center"> 

        </LinearLayout> 

,立即选择我抢喜欢的项目所以并激活它

for(int i = 0; i < totalPhases; i++) { 
     if(i != phasePosition){ 

      phaseListItems.getChildAt(i).setActivated(false); 

      View child = phaseListItems.getChildAt(i); 


     } 
    } 

现在我抓住视图像这样,并在这一点上想要也改变吨ext的颜色,大小如果可能的TextView phaseNumbers和phaseBubbles ImageView中的图片大小...我正在尝试instanceOf的孩子,但是很难正确实施它,让我知道谢谢!

问题: 如何在我的动态添加的线性布局中定位儿童textview和imageview?

+0

请通过正确添加更多代码来澄清您的问题。 –

+0

问题不够清楚 – ribads

+0

更新了这个问题,对不起 – Lion789

回答

2

您可以使用findViewById获取TextView。 所以,你的循环内

TextView tvPhaseNumbers = (TextView)child.FindViewById(R.id. phaseNumbers) 

那么你可以申请任何你需要的tvPhasesNumbers。

+1

这就是它,谢谢! – Lion789

相关问题