2013-03-04 47 views
1

我正在開發的Android應用程序,這是我的第一個應用程序的開發,代碼自來水文本視圖中顯示文本

按我的要求,我需要的代碼圖像中,如下實現UI。

跳轉圖像解釋了我的要求。下面的圖片是App UI視圖。謝謝..

enter image description here

我用下面的代碼,但它無法正常工作。任何人都可以找到故障..

- DrinkActivity.java 

TextView t ; 
public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.activity_drink); 
      t = (TextView)findViewById(R.id.TextView01); 
      t.setOnClickListener((android.view.View.OnClickListener) this); 
      } 
public void onClick(View arg0) { 
      t.setText("My text on click"); 
      } 

- activity_drink.xml 


<LinearLayout 
    android:id="@+id/LinearLayout01" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

</LinearLayout> 

<ListView 
    android:id="@+id/ListView01" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" > 
</ListView> 
<LinearLayout 
    android:id="@+id/LinearLayout02" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

</LinearLayout> 

<TextView android:text="This is my first text" 
android:id="@+id/TextView01" 
android:layout_width="wrap_content" 
android:textStyle="bold" 
android:textSize="28sp" 
android:editable="true" 
android:clickable="true" 
android:layout_height="wrap_content" 
android:onClick="onClick"> 

</TextView> 
+0

您在同一文本視圖中單擊並設置文本。這是故意的 – 2013-03-04 19:37:54

回答

0

你可以通過設計2個片段實現這一目標的行爲:

第一個將只會顯示你的標籤文本的簡單的TextView片段。

2.第二片段將是作爲LinaerLayout垂直佈局將包含2個TextViews一個接一個,首先將是相同的TextView如在第一片段,而第二TextView的將包含標籤的說明。

那麼所有你應該做的是在第一個片段的點擊使用此代碼的第二個替換:

if (!isTabOpen) 
{ 
    fragmentTransaction = fragmentManager.beginTransaction(); 
    fragmentTransaction.remove(TabFragment) 
    .add(R.id.containerForFragments,TabAndDescriptionFragment) 
    .commit(); 
} 
else 
{ 
     fragmentTransaction = fragmentManager.beginTransaction(); 
    fragmentTransaction.remove(TabAndDescriptionFragment) 
    .add(R.id.containerForFragments,TabFragment) 
    .commit(); 
} 

您所創建的plusButtonFragment和userNewFragment後。

+3

這太過於簡單。 – 2013-03-04 19:02:15

+0

帶有onClick實現的簡單TextView將ScrollView的可見性從View.INVISIBLE更改爲View.VISIBLE就足夠了 – 2013-03-04 19:02:58

+0

是的,也許你是對的。但是如果他想重複這個並創建一個完整的滾動視圖呢?我認爲將一個滾動視圖放置在滾動視圖中會出現問題,這樣他可以更加靈活。 – 2013-03-04 19:05:36