2013-05-22 3 views
0

у меня есть 2 .xml в одном я есть ресурс ImageView и именно это:Отправить ImageView в Scrollview

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

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="200dp" 
     android:layout_height="200dp" 

     android:src="@drawable/ic_launcher22" /> 

    <Button android:id="@+id/bSetWall" 
     android:layout_width="200dp" 
     android:layout_height="50dp" 
     android:layout_gravity="center" 
     android:layout_marginTop="400dp" 
     android:gravity="center" 
     android:text="Imposta come sfondo" 

     /> 
</LinearLayout> 

в другой. XML У меня есть ресурс кнопки, а также макет, где он должен пойти ImageView и это:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/LinearLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" > 

<ScrollView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="left" > 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="702dp" 
      android:layout_gravity="left" 
      android:orientation="vertical" > 

    <Button 
     android:id="@+id/bopentx" 
     android:layout_width="100dp" 
     android:layout_height="100dp" 
     android:layout_gravity="left" 
     android:text="tattoo" /> 

    <Button 
     android:id="@+id/bopensax" 
     android:layout_width="100dp" 
     android:layout_height="100dp" 
     android:layout_gravity="left" 
     android:text="sand" /> 

    <Button 
     android:id="@+id/bopenwx" 
     android:layout_width="100dp" 
     android:layout_height="100dp" 
     android:layout_gravity="left" 
     android:text="wet" /> 

    <Button 
     android:id="@+id/bopennx" 
     android:layout_width="100dp" 
     android:layout_height="100dp" 
     android:layout_gravity="left" 
     android:text="naked" /> 

    <Button 
     android:id="@+id/Bopenlx" 
     android:layout_width="100dp" 
     android:layout_height="100dp" 
     android:layout_gravity="left" 
     android:text="loincloth" /> 



    <Button 
     android:id="@+id/Bopenbx" 
     android:layout_width="100dp" 
     android:layout_height="100dp" 
     android:layout_gravity="left" 
     android:text="brazilian" /> 

    </LinearLayout> 
    </ScrollView> 

    <ScrollView 
     android:id="@+id/Scroll1" 
     android:layout_width="200dp" 
     android:layout_height="wrap_content" 
     android:layout_gravity="right" > 

     <LinearLayout 
      android:id="@+id/Linear1" 
      android:layout_width="wrap_content" 
      android:layout_height="702dp" 
      android:layout_gravity="right" 
      android:orientation="vertical" > 

//the image needs to go here when i click the button 


     </LinearLayout> 
    </ScrollView> 

</LinearLayout> 

и в классе меню я использовал это: меню общественного класса расширяет активность реализует View.OnClickListener {

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    Button button1=(Button) findViewById(R.id.bopennx); 


    button1.setOnClickListener(new Button.OnClickListener() { 







     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 

      switch (v.getId()){ 
      case R.id.bopennx: 
       LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
       View view = inflater.inflate(R.layout.activity_main, null); 
       LinearLayout linearLayout = (LinearLayout) view.findViewById(R.id.Linear1); 
       ImageView newImageView=(ImageView)view.findViewById(R.id.imageView1); 
       newImageView.setImageResource(R.drawable.ic_brazilian1); 
       linearLayout.addView(newImageView); 
       break; 



      } 






     }}); 
     } 
+1

Естественно, идентификатор кнопки содержится в том же. xml, куда отправлять фотографии, но в другом макете – Gioele

+0

использовать ImageView newImageView = новый ImageView (this); –

+0

LogCat говорит мне: не удалось найти ресурс благодаря – Gioele

ответ

0

для того, чтобы получить вид из .xml, который отличается от того, который вы установили в contentView (в вашем случае R.layout.main), вы должны надуть XML и поиск мнение внутри xml, который вы надули.

LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
View view = inflater.inflate(R.layout.your_xml, null); 
ImageView imageView = (ImageView) view.findViewById(R.id.imageView1); 
+0

я использовал это: переключатель (v.getId()) { \t \t случай R.id.bopennx: \t \t LayoutInflater инфлятор = (LayoutInflater) getSystemService (Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate (R.layout.activity_main, null); LinearLayout imageScrollLayout = (LinearLayout) view.findViewById (R.id.Linear1); ImageView imageView = (ImageView) view.findViewById (R.id.imageView1); \t \t \t \t \t imageView.setImageResource (R.drawable.ic_brazilian1); \t \t \t \t \t imageScrollLayout.addView (imageView); \t \t \t \t \t break; – Gioele

+0

, но ничего: ((( – Gioele

+0

Можете ли вы обновить свой XML-файл? У вас есть несколько файлов xml? –

Смежные вопросы